From 0bf9a22266e526d538c1db503d8d68a7200ac0b2 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 8 Oct 2024 19:51:48 +0200 Subject: [PATCH] Ci update (#32) * improve CI * update CI * add void * drop php 7.2 --- .github/workflows/ci.yml | 9 +-- .github/workflows/static.yml | 22 +++---- composer.json | 4 +- phpstan-baseline.neon | 10 +-- psalm.baseline.xml | 65 +++---------------- .../CompilerPass/ProxyServiceWithMockPass.php | 2 +- src/DependencyInjection/Configuration.php | 3 - .../HappyrServiceMockingExtension.php | 5 +- src/Generator/Constructor.php | 29 ++++----- .../LazyLoadingValueHolderGenerator.php | 33 ++++------ src/Test/RestoreServiceContainer.php | 1 + 11 files changed, 54 insertions(+), 129 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index afb4c74..6baf9f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,11 +8,8 @@ jobs: strategy: max-parallel: 10 matrix: - php: [ '8.0', '8.1'] - sf_version: [ '5.4.*', '6.0.*'] - include: - - php: 7.2 - sf_version: '5.4.*' + php: [ '8.1', '8.2', '8.3'] + sf_version: [ '5.4.*', '6.4.*'] steps: - name: Set up PHP @@ -41,7 +38,7 @@ jobs: - name: Set up PHP uses: shivammathur/setup-php@2.5.0 with: - php-version: 7.3 + php-version: 8.1 coverage: none - name: Checkout code diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 521f6ce..aaba1d5 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -4,7 +4,7 @@ name: Static analysis jobs: phpstan: name: PHPStan - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout code @@ -13,9 +13,9 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.3 coverage: none - tools: phpstan:1.5.3, cs2pr + tools: phpstan:1.12, cs2pr - name: Download dependencies uses: ramsey/composer-install@v1 @@ -25,7 +25,7 @@ jobs: php-cs-fixer: name: PHP-CS-Fixer - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout code @@ -34,16 +34,16 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.3 coverage: none - tools: php-cs-fixer:3.8.0, cs2pr + tools: php-cs-fixer:3.64, cs2pr - name: PHP-CS-Fixer run: php-cs-fixer fix --dry-run --format=checkstyle | cs2pr psalm: name: Psalm - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 @@ -51,9 +51,9 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.3 coverage: none - tools: vimeo/psalm:4.22.0 + tools: vimeo/psalm:5.26 - name: Download dependencies uses: ramsey/composer-install@v1 @@ -63,13 +63,13 @@ jobs: composer-normalize: name: Composer Normalize - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.3 coverage: none tools: composer-normalize diff --git a/composer.json b/composer.json index 7ac9614..3755bfe 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.2", + "php": ">=8.1", "friendsofphp/proxy-manager-lts": "^1.0", "symfony/config": "^5.4 || ^6.0", "symfony/dependency-injection": "^5.4 || ^6.0", @@ -23,7 +23,7 @@ }, "require-dev": { "nyholm/symfony-bundle-test": "^2.0", - "symfony/phpunit-bridge": "^6.0" + "symfony/phpunit-bridge": "^6.4.11" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 171b24e..5152971 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5,11 +5,6 @@ parameters: count: 1 path: src/DependencyInjection/CompilerPass/ProxyServiceWithMockPass.php - - - message: "#^Parameter \\#1 \\$class of method Symfony\\\\Component\\\\DependencyInjection\\\\Definition\\:\\:setClass\\(\\) expects string\\|null, false given\\.$#" - count: 1 - path: src/DependencyInjection/CompilerPass/ProxyServiceWithMockPass.php - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" count: 1 @@ -25,3 +20,8 @@ parameters: count: 1 path: src/ServiceMock.php + - + message: "#^Parameter \\#1 \\$initializer of method ProxyManager\\\\Proxy\\\\LazyLoadingInterface\\\\:\\:setProxyInitializer\\(\\) expects \\(Closure\\(object\\|null\\=, ProxyManager\\\\Proxy\\\\LazyLoadingInterface\\\\=, string\\=, array\\\\=, Closure\\|null\\=, array\\\\=\\)\\: bool\\)\\|null, Closure\\(mixed, ProxyManager\\\\Proxy\\\\LazyLoadingInterface, mixed, array, mixed\\)\\: true given\\.$#" + count: 1 + path: src/ServiceMock.php + diff --git a/psalm.baseline.xml b/psalm.baseline.xml index ce443d5..d90c9cd 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -1,62 +1,13 @@ - + + + + + + - - getWrappedValueHolderValue + + - - - $interface - $interface - ) - ) - fn - fn - - - - - , - , - => - fn - - - - - $item1 - ) - fn - - - - - $left - $type - $type - $type - ) - ) - ) - ) - , - , - , - fn - fn - fn - fn - - - - - $type - $type - ) - ) - fn - fn - - diff --git a/src/DependencyInjection/CompilerPass/ProxyServiceWithMockPass.php b/src/DependencyInjection/CompilerPass/ProxyServiceWithMockPass.php index 664c4ba..1e3fa0e 100644 --- a/src/DependencyInjection/CompilerPass/ProxyServiceWithMockPass.php +++ b/src/DependencyInjection/CompilerPass/ProxyServiceWithMockPass.php @@ -11,7 +11,7 @@ class ProxyServiceWithMockPass implements CompilerPassInterface { - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { /** @var array $serviceIds */ $serviceIds = $container->getParameter('happyr_service_mock.services'); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 4215f41..c91d9cc 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -7,9 +7,6 @@ class Configuration implements ConfigurationInterface { - /** - * {@inheritdoc} - */ public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('happyr_service_mocking'); diff --git a/src/DependencyInjection/HappyrServiceMockingExtension.php b/src/DependencyInjection/HappyrServiceMockingExtension.php index aaff4e3..a3a4e44 100644 --- a/src/DependencyInjection/HappyrServiceMockingExtension.php +++ b/src/DependencyInjection/HappyrServiceMockingExtension.php @@ -7,10 +7,7 @@ class HappyrServiceMockingExtension extends Extension { - /** - * {@inheritdoc} - */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); diff --git a/src/Generator/Constructor.php b/src/Generator/Constructor.php index e308cb8..5387dde 100644 --- a/src/Generator/Constructor.php +++ b/src/Generator/Constructor.php @@ -4,9 +4,6 @@ namespace Happyr\ServiceMocking\Generator; -use function array_filter; -use function array_map; -use function implode; use Laminas\Code\Generator\Exception\InvalidArgumentException; use Laminas\Code\Generator\PropertyGenerator; use Laminas\Code\Reflection\MethodReflection; @@ -14,10 +11,6 @@ use ProxyManager\Generator\MethodGenerator; use ProxyManager\ProxyGenerator\Util\Properties; use ProxyManager\ProxyGenerator\Util\UnsetPropertiesGenerator; -use ReflectionClass; -use ReflectionMethod; -use function reset; -use function var_export; /** * The `__construct` implementation for lazy loading proxies. @@ -29,7 +22,7 @@ class Constructor extends MethodGenerator /** * @throws InvalidArgumentException */ - public static function generateMethod(ReflectionClass $originalClass, PropertyGenerator $valueHolder): self + public static function generateMethod(\ReflectionClass $originalClass, PropertyGenerator $valueHolder): self { $originalConstructor = self::getConstructor($originalClass); @@ -41,7 +34,7 @@ public static function generateMethod(ReflectionClass $originalClass, PropertyGe 'static $reflection;'."\n\n" .'if (! $this->'.$valueHolder->getName().') {'."\n" .' $reflection = $reflection ?? new \ReflectionClass(' - .var_export($originalClass->getName(), true) + .\var_export($originalClass->getName(), true) .");\n" .' $this->'.$valueHolder->getName().' = $reflection->newInstanceWithoutConstructor();'."\n" .UnsetPropertiesGenerator::generateSnippet(Properties::fromReflectionClass($originalClass), 'this') @@ -56,13 +49,13 @@ public static function generateMethod(ReflectionClass $originalClass, PropertyGe private static function generateOriginalConstructorCall( MethodReflection $originalConstructor, - PropertyGenerator $valueHolder + PropertyGenerator $valueHolder, ): string { return "\n\n" .'$this->'.$valueHolder->getName().'->'.$originalConstructor->getName().'(' - .implode( + .\implode( ', ', - array_map( + \array_map( static function (ParameterReflection $parameter): string { return ($parameter->isVariadic() ? '...' : '').'$'.$parameter->getName(); }, @@ -72,23 +65,23 @@ static function (ParameterReflection $parameter): string { .');'; } - private static function getConstructor(ReflectionClass $class): ?MethodReflection + private static function getConstructor(\ReflectionClass $class): ?MethodReflection { - $constructors = array_map( - static function (ReflectionMethod $method): MethodReflection { + $constructors = \array_map( + static function (\ReflectionMethod $method): MethodReflection { return new MethodReflection( $method->getDeclaringClass()->getName(), $method->getName() ); }, - array_filter( + \array_filter( $class->getMethods(), - static function (ReflectionMethod $method): bool { + static function (\ReflectionMethod $method): bool { return $method->isConstructor(); } ) ); - return reset($constructors) ?: null; + return \reset($constructors) ?: null; } } diff --git a/src/Generator/LazyLoadingValueHolderGenerator.php b/src/Generator/LazyLoadingValueHolderGenerator.php index 34b05ae..4d9afc4 100644 --- a/src/Generator/LazyLoadingValueHolderGenerator.php +++ b/src/Generator/LazyLoadingValueHolderGenerator.php @@ -4,11 +4,6 @@ namespace Happyr\ServiceMocking\Generator; -use function array_map; -use function array_merge; -use function func_get_arg; -use function func_num_args; -use InvalidArgumentException; use Laminas\Code\Generator\ClassGenerator; use Laminas\Code\Generator\MethodGenerator; use Laminas\Code\Reflection\MethodReflection; @@ -37,13 +32,9 @@ use ProxyManager\ProxyGenerator\Util\Properties; use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter; use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue; -use ReflectionClass; -use ReflectionMethod; -use function str_replace; -use function substr; /** - * Generator for proxies implementing {@see \ProxyManager\Proxy\VirtualProxyInterface}. + * Generator for proxies implementing {@see VirtualProxyInterface}. * * This is a 99% copy of ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator. * This class generates a different constructor. @@ -55,19 +46,17 @@ class LazyLoadingValueHolderGenerator implements ProxyGeneratorInterface { /** - * {@inheritDoc} - * * @return void * * @throws InvalidProxiedClassException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * * @psalm-param array{skipDestructor?: bool, fluentSafe?: bool} $proxyOptions */ - public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator/* , array $proxyOptions = [] */) + public function generate(\ReflectionClass $originalClass, ClassGenerator $classGenerator/* , array $proxyOptions = [] */) { /** @psalm-var array{skipDestructor?: bool, fluentSafe?: bool} $proxyOptions */ - $proxyOptions = func_num_args() >= 3 ? func_get_arg(2) : []; + $proxyOptions = \func_num_args() >= 3 ? \func_get_arg(2) : []; CanProxyAssertion::assertClassCanBeProxied($originalClass); @@ -92,12 +81,12 @@ public function generate(ReflectionClass $originalClass, ClassGenerator $classGe $excludedMethods[] = '__destruct'; } - array_map( + \array_map( static function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator): void { ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod); }, - array_merge( - array_map( + \array_merge( + \array_map( $this->buildLazyLoadingMethodInterceptor($initializer, $valueHolder, $proxyOptions['fluentSafe'] ?? false), ProxiedMethodsFilter::getProxiedMethods($originalClass, $excludedMethods) ), @@ -126,9 +115,9 @@ static function (MethodGenerator $generatedMethod) use ($originalClass, $classGe private function buildLazyLoadingMethodInterceptor( InitializerProperty $initializer, ValueHolderProperty $valueHolder, - bool $fluentSafe + bool $fluentSafe, ): callable { - return static function (ReflectionMethod $method) use ($initializer, $valueHolder, $fluentSafe): LazyLoadingMethodInterceptor { + return static function (\ReflectionMethod $method) use ($initializer, $valueHolder, $fluentSafe): LazyLoadingMethodInterceptor { $byRef = $method->returnsReference() ? '& ' : ''; $method = LazyLoadingMethodInterceptor::generateMethod( new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), @@ -139,11 +128,11 @@ private function buildLazyLoadingMethodInterceptor( if ($fluentSafe) { $valueHolderName = '$this->'.$valueHolder->getName(); $body = $method->getBody(); - $newBody = str_replace('return '.$valueHolderName, 'if ('.$valueHolderName.' === $returnValue = '.$byRef.$valueHolderName, $body); + $newBody = \str_replace('return '.$valueHolderName, 'if ('.$valueHolderName.' === $returnValue = '.$byRef.$valueHolderName, $body); if ($newBody !== $body) { $method->setBody( - substr($newBody, 0, -1).') {'."\n" + \substr($newBody, 0, -1).') {'."\n" .' return $this;'."\n" .'}'."\n\n" .'return $returnValue;' diff --git a/src/Test/RestoreServiceContainer.php b/src/Test/RestoreServiceContainer.php index 1a0238e..0f4aab7 100644 --- a/src/Test/RestoreServiceContainer.php +++ b/src/Test/RestoreServiceContainer.php @@ -14,6 +14,7 @@ trait RestoreServiceContainer { /** * @internal + * * @after */ public static function _restoreContainer(): void