From 70578f81f3d925c14ab7d08d3bfb9fa4711c0b6e Mon Sep 17 00:00:00 2001 From: Reinfi Date: Sun, 12 Feb 2023 09:16:00 +0100 Subject: [PATCH 01/14] minimum requirement is not php 8.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6e23114..9d6100b 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "bin/zf-dependency-injection-cache-warmup" ], "require": { - "php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0", + "php": "~8.1.0 || ~8.2.0", "laminas/laminas-servicemanager": "^2.7 | ^3.0", "laminas/laminas-modulemanager": "^2.7", "psr/simple-cache": "^1.0" From 93ff4c158ef761fa49475427dd5632dfa4eb7d8b Mon Sep 17 00:00:00 2001 From: Reinfi Date: Sat, 4 Mar 2023 09:13:04 +0100 Subject: [PATCH 02/14] add return types for methods --- src/Annotation/AbstractInjectPluginManager.php | 2 +- src/Annotation/Inject.php | 7 ++----- src/Annotation/InjectConfig.php | 2 +- src/Annotation/InjectConstant.php | 7 ++----- src/Annotation/InjectContainer.php | 2 +- src/Annotation/InjectDoctrineRepository.php | 3 ++- src/Annotation/InjectParent.php | 7 ++----- src/Attribute/AbstractInjectPluginManager.php | 2 +- src/Attribute/Inject.php | 2 +- src/Attribute/InjectConfig.php | 2 +- src/Attribute/InjectConstant.php | 2 +- src/Attribute/InjectContainer.php | 2 +- src/Attribute/InjectDoctrineRepository.php | 3 ++- src/Attribute/InjectParent.php | 2 +- src/Extension/PHPStan/ServiceManagerLoader.php | 5 +---- src/Injection/AutoWiring.php | 3 +-- src/Injection/AutoWiringPluginManager.php | 10 +++++----- src/Injection/InjectionInterface.php | 5 +---- src/Injection/Value.php | 12 +++--------- .../AutoWiring/Factory/ResolverServiceFactory.php | 2 +- src/Service/AutoWiring/LazyResolverService.php | 2 -- 21 files changed, 31 insertions(+), 53 deletions(-) diff --git a/src/Annotation/AbstractInjectPluginManager.php b/src/Annotation/AbstractInjectPluginManager.php index 3bc64c1..d334170 100644 --- a/src/Annotation/AbstractInjectPluginManager.php +++ b/src/Annotation/AbstractInjectPluginManager.php @@ -34,7 +34,7 @@ public function __construct(array $values) $this->name = $values['value']; } - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { $container = $this->determineContainer($container); $pluginManagerImplementation = $container->get(static::PLUGIN_MANAGER); diff --git a/src/Annotation/Inject.php b/src/Annotation/Inject.php index 0c33b84..126e8d3 100644 --- a/src/Annotation/Inject.php +++ b/src/Annotation/Inject.php @@ -14,12 +14,9 @@ */ final class Inject implements AnnotationInterface { - /** - * @var string - */ - public $value; + public string $value; - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { return $container->get($this->value); } diff --git a/src/Annotation/InjectConfig.php b/src/Annotation/InjectConfig.php index 10c7c0c..a72baa9 100644 --- a/src/Annotation/InjectConfig.php +++ b/src/Annotation/InjectConfig.php @@ -29,7 +29,7 @@ public function __construct(array $values) $this->configPath = $values['value']; } - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { $container = $this->determineContainer($container); diff --git a/src/Annotation/InjectConstant.php b/src/Annotation/InjectConstant.php index 411c99f..94b65c3 100644 --- a/src/Annotation/InjectConstant.php +++ b/src/Annotation/InjectConstant.php @@ -14,12 +14,9 @@ */ final class InjectConstant implements AnnotationInterface { - /** - * @var string - */ - public $value; + public string $value; - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { return constant($this->value); } diff --git a/src/Annotation/InjectContainer.php b/src/Annotation/InjectContainer.php index 8bc5efd..b62031d 100644 --- a/src/Annotation/InjectContainer.php +++ b/src/Annotation/InjectContainer.php @@ -14,7 +14,7 @@ */ final class InjectContainer implements AnnotationInterface { - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { return $container; } diff --git a/src/Annotation/InjectDoctrineRepository.php b/src/Annotation/InjectDoctrineRepository.php index 69b5ce9..9da0fde 100644 --- a/src/Annotation/InjectDoctrineRepository.php +++ b/src/Annotation/InjectDoctrineRepository.php @@ -4,6 +4,7 @@ namespace Reinfi\DependencyInjection\Annotation; +use Doctrine\ORM\EntityRepository; use Psr\Container\ContainerInterface; use Reinfi\DependencyInjection\Exception\AutoWiringNotPossibleException; @@ -34,7 +35,7 @@ public function __construct(array $values) $this->entity = $values['value']; } - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): EntityRepository { $container = $this->determineContainer($container); diff --git a/src/Annotation/InjectParent.php b/src/Annotation/InjectParent.php index 7d5bec9..1af27ac 100644 --- a/src/Annotation/InjectParent.php +++ b/src/Annotation/InjectParent.php @@ -15,12 +15,9 @@ */ final class InjectParent implements AnnotationInterface { - /** - * @var string - */ - public $value; + public string $value; - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { if ($container instanceof AbstractPluginManager) { $container = $container->getServiceLocator(); diff --git a/src/Attribute/AbstractInjectPluginManager.php b/src/Attribute/AbstractInjectPluginManager.php index 07d7089..56122ce 100644 --- a/src/Attribute/AbstractInjectPluginManager.php +++ b/src/Attribute/AbstractInjectPluginManager.php @@ -25,7 +25,7 @@ public function __construct(string $name, ?array $options = null) $this->options = $options; } - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { $container = $this->determineContainer($container); $pluginManagerImplementation = $container->get(static::PLUGIN_MANAGER); diff --git a/src/Attribute/Inject.php b/src/Attribute/Inject.php index de2da4d..21ad16f 100644 --- a/src/Attribute/Inject.php +++ b/src/Attribute/Inject.php @@ -21,7 +21,7 @@ public function __construct(string $value) $this->value = $value; } - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { return $container->get($this->value); } diff --git a/src/Attribute/InjectConfig.php b/src/Attribute/InjectConfig.php index c7bd6d0..45bec33 100644 --- a/src/Attribute/InjectConfig.php +++ b/src/Attribute/InjectConfig.php @@ -25,7 +25,7 @@ public function __construct(string $configPath, bool $asArray = false) $this->asArray = $asArray; } - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { $container = $this->determineContainer($container); diff --git a/src/Attribute/InjectConstant.php b/src/Attribute/InjectConstant.php index d3f9267..ad7181a 100644 --- a/src/Attribute/InjectConstant.php +++ b/src/Attribute/InjectConstant.php @@ -21,7 +21,7 @@ public function __construct(string $value) $this->value = $value; } - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { return constant($this->value); } diff --git a/src/Attribute/InjectContainer.php b/src/Attribute/InjectContainer.php index 930dd9f..ac736a1 100644 --- a/src/Attribute/InjectContainer.php +++ b/src/Attribute/InjectContainer.php @@ -14,7 +14,7 @@ #[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] final class InjectContainer implements InjectionInterface { - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): ContainerInterface { return $container; } diff --git a/src/Attribute/InjectDoctrineRepository.php b/src/Attribute/InjectDoctrineRepository.php index a89e4e5..0f1a51a 100644 --- a/src/Attribute/InjectDoctrineRepository.php +++ b/src/Attribute/InjectDoctrineRepository.php @@ -5,6 +5,7 @@ namespace Reinfi\DependencyInjection\Attribute; use Attribute; +use Doctrine\ORM\EntityRepository; use Psr\Container\ContainerInterface; use Reinfi\DependencyInjection\Exception\AutoWiringNotPossibleException; @@ -27,7 +28,7 @@ public function __construct(string $entity, ?string $entityManager = null) } } - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): EntityRepository { $container = $this->determineContainer($container); diff --git a/src/Attribute/InjectParent.php b/src/Attribute/InjectParent.php index cf26d6e..4a8e580 100644 --- a/src/Attribute/InjectParent.php +++ b/src/Attribute/InjectParent.php @@ -22,7 +22,7 @@ public function __construct(string $value) $this->value = $value; } - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { if ($container instanceof AbstractPluginManager) { $container = $container->getServiceLocator(); diff --git a/src/Extension/PHPStan/ServiceManagerLoader.php b/src/Extension/PHPStan/ServiceManagerLoader.php index 6765de3..160d3fc 100644 --- a/src/Extension/PHPStan/ServiceManagerLoader.php +++ b/src/Extension/PHPStan/ServiceManagerLoader.php @@ -10,10 +10,7 @@ final class ServiceManagerLoader { - /** - * @var ServiceManager|null - */ - private $serviceLocator = null; + private ?ServiceManager $serviceLocator = null; public function __construct(?string $serviceManagerLoader) { diff --git a/src/Injection/AutoWiring.php b/src/Injection/AutoWiring.php index 8ea3ec1..341d1ca 100644 --- a/src/Injection/AutoWiring.php +++ b/src/Injection/AutoWiring.php @@ -21,10 +21,9 @@ public function __construct(string $serviceName) } /** - * @return mixed * @throws AutoWiringNotPossibleException */ - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { if ($container->has($this->serviceName)) { return $container->get($this->serviceName); diff --git a/src/Injection/AutoWiringPluginManager.php b/src/Injection/AutoWiringPluginManager.php index 7472f62..6704fe3 100644 --- a/src/Injection/AutoWiringPluginManager.php +++ b/src/Injection/AutoWiringPluginManager.php @@ -29,18 +29,18 @@ public function __construct( * @return mixed * @throws AutoWiringNotPossibleException */ - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { if ($container instanceof AbstractPluginManager) { $container = $container->getServiceLocator(); } - $pluginManagerImplemenation = $container->get($this->pluginManager); + $pluginManagerImplementation = $container->get($this->pluginManager); if ( - $pluginManagerImplemenation instanceof ContainerInterface - && $pluginManagerImplemenation->has($this->serviceName) + $pluginManagerImplementation instanceof ContainerInterface + && $pluginManagerImplementation->has($this->serviceName) ) { - return $pluginManagerImplemenation->get($this->serviceName); + return $pluginManagerImplementation->get($this->serviceName); } throw new AutoWiringNotPossibleException($this->serviceName); diff --git a/src/Injection/InjectionInterface.php b/src/Injection/InjectionInterface.php index a6d9fbe..8e55256 100644 --- a/src/Injection/InjectionInterface.php +++ b/src/Injection/InjectionInterface.php @@ -13,8 +13,5 @@ */ interface InjectionInterface { - /** - * @return mixed - */ - public function __invoke(ContainerInterface $container); + public function __invoke(ContainerInterface $container): mixed; } diff --git a/src/Injection/Value.php b/src/Injection/Value.php index 05cf3b4..690d1d5 100644 --- a/src/Injection/Value.php +++ b/src/Injection/Value.php @@ -11,20 +11,14 @@ */ class Value implements InjectionInterface { - /** - * @var mixed - */ - private $value; + private mixed $value; - /** - * @param mixed $value - */ - public function __construct($value) + public function __construct(mixed $value) { $this->value = $value; } - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): mixed { return $this->value; } diff --git a/src/Service/AutoWiring/Factory/ResolverServiceFactory.php b/src/Service/AutoWiring/Factory/ResolverServiceFactory.php index 53d4d1c..0a6da82 100644 --- a/src/Service/AutoWiring/Factory/ResolverServiceFactory.php +++ b/src/Service/AutoWiring/Factory/ResolverServiceFactory.php @@ -37,7 +37,7 @@ public function __invoke(ContainerInterface $container): ResolverService } /** - * @return class-string[] + * @return class-string[] */ private function getResolverStack(array $config): array { diff --git a/src/Service/AutoWiring/LazyResolverService.php b/src/Service/AutoWiring/LazyResolverService.php index 984aee1..b02eed3 100644 --- a/src/Service/AutoWiring/LazyResolverService.php +++ b/src/Service/AutoWiring/LazyResolverService.php @@ -7,8 +7,6 @@ use Psr\Container\ContainerInterface; /** - * Class LazyResolverService - * * @package Reinfi\DependencyInjection\Service\AutoWiring */ class LazyResolverService implements ResolverServiceInterface From 5ece583cbfaa57df7ba17495789caccc8c764eec Mon Sep 17 00:00:00 2001 From: Reinfi Date: Sat, 4 Mar 2023 09:13:34 +0100 Subject: [PATCH 03/14] only run php from 8.1 upwards in ci pipeline --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0061dfd..082a9a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false max-parallel: 3 matrix: - php: ['7.4', '8.0', '8.1', '8.2'] + php: ['8.1', '8.2'] name: PHP ${{ matrix.php }} ${{ matrix.description }} steps: - name: Checkout From 74e17efcb9ebf083597f7f9c6dda5bec3c58a7a1 Mon Sep 17 00:00:00 2001 From: Reinfi Date: Sun, 5 Mar 2023 17:13:16 +0100 Subject: [PATCH 04/14] fix codestyle --- src/Injection/AutoWiringPluginManager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Injection/AutoWiringPluginManager.php b/src/Injection/AutoWiringPluginManager.php index 6704fe3..e21f78e 100644 --- a/src/Injection/AutoWiringPluginManager.php +++ b/src/Injection/AutoWiringPluginManager.php @@ -26,7 +26,6 @@ public function __construct( } /** - * @return mixed * @throws AutoWiringNotPossibleException */ public function __invoke(ContainerInterface $container): mixed From 99ce2b6038c717fa6b1a19370ff9fbe02b8d95d7 Mon Sep 17 00:00:00 2001 From: Reinfi Date: Sun, 5 Mar 2023 17:28:07 +0100 Subject: [PATCH 05/14] run coverage on php8.1 --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 3d64d82..c704eaf 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false max-parallel: 1 matrix: - php: ['8.0'] + php: ['8.1'] name: PHP ${{ matrix.php }} ${{ matrix.description }} steps: - name: Checkout From 6fc77b9e44719ae49b5fba8bda9eeec56b328eaf Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:42:47 +0000 Subject: [PATCH 06/14] Update codecov/codecov-action action to v3 --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index c704eaf..592ba71 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -45,7 +45,7 @@ jobs: # https://github.com/marketplace/actions/codecov - name: Submit coverage report - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v3 with: files: build/coverage.xml verbose: true From b6791c8342a405c42a7c2c7e5a2b8dac2b720a74 Mon Sep 17 00:00:00 2001 From: Soheil Nazari <113988347+s0h311@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:01:00 +0200 Subject: [PATCH 07/14] fixed typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9fa9b97..b7d988d 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Heavily inspired by https://github.com/mikemix/mxdiModule. ### Installation 1. Install with Composer: `composer require reinfi/zf-dependency-injection`. -2. Enable the module via config in `appliation.config.php` under `modules` key: +2. Enable the module via config in `application.config.php` under `modules` key: ```php return [ From 86e0b830853d0effbf0ba214db5a42a21fac9acb Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 25 Jul 2023 16:32:04 +0000 Subject: [PATCH 08/14] Update dependency symplify/easy-coding-standard to v12 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9d6100b..59facea 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,7 @@ "laminas/laminas-form": "^3.0", "laminas/laminas-inputfilter": "^2.12", "bnf/phpstan-psr-container": "^1.0", - "symplify/easy-coding-standard": "^11.2", + "symplify/easy-coding-standard": "^12.0", "doctrine/annotations": "^2.0" }, "extra": { From 6c79e3a17b273ec6b8e040ec5d18d40245be1eb8 Mon Sep 17 00:00:00 2001 From: Reinfi Date: Sun, 24 Sep 2023 16:10:17 +0200 Subject: [PATCH 09/14] allow extractors to be array of extractors instead of single one --- CHANGELOG.md | 2 + .../Extractor/Factory/ExtractorFactory.php | 48 ++++++++++------- .../Factory/ExtractorFactoryTest.php | 51 +++++++++++++++++++ 3 files changed, 83 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d77aef..2afcd19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ ## Changelog +### v5.5.0 +- extractor configuration can now contain an array of extractors ### v5.0.0 - deprecated PHP 7.3 - add PHP 8.1 diff --git a/src/Service/Extractor/Factory/ExtractorFactory.php b/src/Service/Extractor/Factory/ExtractorFactory.php index 679e725..bdfd1fc 100644 --- a/src/Service/Extractor/Factory/ExtractorFactory.php +++ b/src/Service/Extractor/Factory/ExtractorFactory.php @@ -22,13 +22,7 @@ public function __invoke(ContainerInterface $container): ExtractorInterface /** @var array $config */ $config = $container->get(ModuleConfig::class); - $extractors = []; - - $extractorFromConfig = $this->extractorFromConfig($container, $config); - - if ($extractorFromConfig instanceof ExtractorInterface) { - $extractors[] = $extractorFromConfig; - } + $extractors = $this->extractorsFromConfig($container, $config); if (class_exists('Doctrine\Common\Annotations\AnnotationReader')) { $extractors[] = $container->get(AnnotationExtractor::class); @@ -41,27 +35,45 @@ public function __invoke(ContainerInterface $container): ExtractorInterface return new ExtractorChain($extractors); } - private function extractorFromConfig( + /** + * @return ExtractorInterface[] + */ + private function extractorsFromConfig( ContainerInterface $container, array $config - ): ?ExtractorInterface { + ): array { $extractorConfiguration = $config['extractor'] ?? null; if ($extractorConfiguration === null) { - return null; + return []; } - $extractor = $container->get($extractorConfiguration); + if (! is_string($extractorConfiguration) && ! is_array($extractorConfiguration)) { + throw new InvalidArgumentException( + 'Configuration property "extractor" must be of either string or array of strings' + ); + } - if ($extractor instanceof ExtractorInterface) { - return $extractor; + if (is_string($extractorConfiguration)) { + $extractorConfiguration = [$extractorConfiguration]; } - throw new InvalidArgumentException( - sprintf( - 'Configuration property "extractor" must be of type %s', - ExtractorInterface::class - ) + return array_map( + function (string $extractorClassName) use ($container): ExtractorInterface { + $extractor = $container->get($extractorClassName); + + if ($extractor instanceof ExtractorInterface) { + return $extractor; + } + + throw new InvalidArgumentException( + sprintf( + 'Configuration property "extractor" must be of type %s', + ExtractorInterface::class + ) + ); + }, + $extractorConfiguration ); } } diff --git a/test/Unit/Service/Extractor/Factory/ExtractorFactoryTest.php b/test/Unit/Service/Extractor/Factory/ExtractorFactoryTest.php index a82d53b..5109b73 100644 --- a/test/Unit/Service/Extractor/Factory/ExtractorFactoryTest.php +++ b/test/Unit/Service/Extractor/Factory/ExtractorFactoryTest.php @@ -73,6 +73,57 @@ public function testItReturnsExtractorDefinedInConfig(): void self::assertContainsOnlyInstancesOf(ExtractorInterface::class, $chain); } + public function testItReturnsArrayOfExtractorsDefinedInConfig(): void + { + $isPhp8OrAbove = version_compare(PHP_VERSION, '8.0.0') >= 0; + + $moduleConfig = new Config([ + 'extractor' => [ + YamlExtractor::class, + ], + ]); + + $yamlExtractor = $this->prophesize(YamlExtractor::class); + $annotationExtractor = $this->prophesize(AnnotationExtractor::class); + $attributeExtractor = $this->prophesize(AttributeExtractor::class); + $container = $this->prophesize(ContainerInterface::class); + + $container->get(ModuleConfig::class) + ->willReturn($moduleConfig->toArray()) + ->shouldBeCalled(); + $container->get(YamlExtractor::class) + ->willReturn($yamlExtractor->reveal()) + ->shouldBeCalled(); + $container->get(AnnotationExtractor::class) + ->willReturn($annotationExtractor->reveal()) + ->shouldBeCalled(); + $container->get(AttributeExtractor::class) + ->willReturn($attributeExtractor->reveal()) + ->shouldBeCalledTimes($isPhp8OrAbove ? 1 : 0); + + $factory = new ExtractorFactory(); + + $extractor = $factory($container->reveal()); + + self::assertInstanceOf(ExtractorChain::class, $extractor); + + $reflectionClass = new ReflectionClass($extractor); + $chainProperty = $reflectionClass->getProperty('chain'); + $chainProperty->setAccessible(true); + + $chain = $chainProperty->getValue($extractor); + + self::assertTrue(is_array($chain)); + + if ($isPhp8OrAbove) { + self::assertCount(3, $chain); + } else { + self::assertCount(2, $chain); + } + + self::assertContainsOnlyInstancesOf(ExtractorInterface::class, $chain); + } + public function testItReturnsAnnotationExtractorIfNoneDefined(): void { $isPhp8OrAbove = version_compare(PHP_VERSION, '8.0.0') >= 0; From cf900abcc4e42203340d1eead7873b83f2aee7d2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 14:28:18 +0000 Subject: [PATCH 10/14] Update actions/checkout action to v4 --- .github/workflows/ci.yml | 2 +- .github/workflows/coverage.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 082a9a8..1481051 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: name: PHP ${{ matrix.php }} ${{ matrix.description }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 592ba71..c25b56a 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -19,7 +19,7 @@ jobs: name: PHP ${{ matrix.php }} ${{ matrix.description }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 From 1ffe734a919dc44cb8f4c16ce202c9f2f602e133 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:16:16 +0000 Subject: [PATCH 11/14] Update dependency ubuntu to v22 --- .github/workflows/ci.yml | 2 +- .github/workflows/coverage.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1481051..c7f2d07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: jobs: run: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 env: extensions: intl,mbstring strategy: diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index c25b56a..c6ad76f 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -8,7 +8,7 @@ on: jobs: run: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 env: extensions: intl,mbstring strategy: From 70a891a656c0e05df2686c1f502f1ed216145f43 Mon Sep 17 00:00:00 2001 From: Reinfi Date: Sat, 21 Oct 2023 14:37:46 +0200 Subject: [PATCH 12/14] add changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2afcd19..41c27ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ ## Changelog +### v6.0.0 +- minimum required PHP version 8.1 +- added return types where possible ### v5.5.0 - extractor configuration can now contain an array of extractors ### v5.0.0 From e0369855087b5f6c124b8098a4c2d24008ca2e77 Mon Sep 17 00:00:00 2001 From: Reinfi Date: Sat, 21 Oct 2023 14:43:19 +0200 Subject: [PATCH 13/14] always return attribute extractor --- .../Extractor/Factory/ExtractorFactory.php | 4 +-- .../Factory/ExtractorFactoryTest.php | 30 ++++--------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/Service/Extractor/Factory/ExtractorFactory.php b/src/Service/Extractor/Factory/ExtractorFactory.php index bdfd1fc..668d14c 100644 --- a/src/Service/Extractor/Factory/ExtractorFactory.php +++ b/src/Service/Extractor/Factory/ExtractorFactory.php @@ -28,9 +28,7 @@ public function __invoke(ContainerInterface $container): ExtractorInterface $extractors[] = $container->get(AnnotationExtractor::class); } - if (version_compare(PHP_VERSION, '8.0.0') >= 0) { - $extractors[] = $container->get(AttributeExtractor::class); - } + $extractors[] = $container->get(AttributeExtractor::class); return new ExtractorChain($extractors); } diff --git a/test/Unit/Service/Extractor/Factory/ExtractorFactoryTest.php b/test/Unit/Service/Extractor/Factory/ExtractorFactoryTest.php index 5109b73..9edebd4 100644 --- a/test/Unit/Service/Extractor/Factory/ExtractorFactoryTest.php +++ b/test/Unit/Service/Extractor/Factory/ExtractorFactoryTest.php @@ -26,8 +26,6 @@ class ExtractorFactoryTest extends TestCase public function testItReturnsExtractorDefinedInConfig(): void { - $isPhp8OrAbove = version_compare(PHP_VERSION, '8.0.0') >= 0; - $moduleConfig = new Config([ 'extractor' => YamlExtractor::class, ]); @@ -48,7 +46,7 @@ public function testItReturnsExtractorDefinedInConfig(): void ->shouldBeCalled(); $container->get(AttributeExtractor::class) ->willReturn($attributeExtractor->reveal()) - ->shouldBeCalledTimes($isPhp8OrAbove ? 1 : 0); + ->shouldBeCalled(); $factory = new ExtractorFactory(); @@ -64,19 +62,13 @@ public function testItReturnsExtractorDefinedInConfig(): void self::assertTrue(is_array($chain)); - if ($isPhp8OrAbove) { - self::assertCount(3, $chain); - } else { - self::assertCount(2, $chain); - } + self::assertCount(3, $chain); self::assertContainsOnlyInstancesOf(ExtractorInterface::class, $chain); } public function testItReturnsArrayOfExtractorsDefinedInConfig(): void { - $isPhp8OrAbove = version_compare(PHP_VERSION, '8.0.0') >= 0; - $moduleConfig = new Config([ 'extractor' => [ YamlExtractor::class, @@ -99,7 +91,7 @@ public function testItReturnsArrayOfExtractorsDefinedInConfig(): void ->shouldBeCalled(); $container->get(AttributeExtractor::class) ->willReturn($attributeExtractor->reveal()) - ->shouldBeCalledTimes($isPhp8OrAbove ? 1 : 0); + ->shouldBeCalled(); $factory = new ExtractorFactory(); @@ -115,19 +107,13 @@ public function testItReturnsArrayOfExtractorsDefinedInConfig(): void self::assertTrue(is_array($chain)); - if ($isPhp8OrAbove) { - self::assertCount(3, $chain); - } else { - self::assertCount(2, $chain); - } + self::assertCount(3, $chain); self::assertContainsOnlyInstancesOf(ExtractorInterface::class, $chain); } public function testItReturnsAnnotationExtractorIfNoneDefined(): void { - $isPhp8OrAbove = version_compare(PHP_VERSION, '8.0.0') >= 0; - $moduleConfig = new Config([]); $annotationExtractor = $this->prophesize(AnnotationExtractor::class); @@ -142,7 +128,7 @@ public function testItReturnsAnnotationExtractorIfNoneDefined(): void ->shouldBeCalled(); $container->get(AttributeExtractor::class) ->willReturn($attributeExtractor->reveal()) - ->shouldBeCalledTimes($isPhp8OrAbove ? 1 : 0); + ->shouldBeCalled(); $factory = new ExtractorFactory(); @@ -158,11 +144,7 @@ public function testItReturnsAnnotationExtractorIfNoneDefined(): void self::assertTrue(is_array($chain)); - if ($isPhp8OrAbove) { - self::assertCount(2, $chain); - } else { - self::assertCount(1, $chain); - } + self::assertCount(2, $chain); self::assertInstanceOf(AnnotationExtractor::class, $chain[0]); From 261aa61d482a195465de4e4c59363a61352b479a Mon Sep 17 00:00:00 2001 From: Reinfi Date: Sat, 21 Oct 2023 14:46:13 +0200 Subject: [PATCH 14/14] allow all psr cache versions --- composer.json | 2 +- src/Service/Cache/Memory.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 59facea..6f03b62 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php": "~8.1.0 || ~8.2.0", "laminas/laminas-servicemanager": "^2.7 | ^3.0", "laminas/laminas-modulemanager": "^2.7", - "psr/simple-cache": "^1.0" + "psr/simple-cache": "^1.0 | ^2.0 | ^3.0" }, "autoload": { "psr-4": { diff --git a/src/Service/Cache/Memory.php b/src/Service/Cache/Memory.php index fd14422..dfda030 100644 --- a/src/Service/Cache/Memory.php +++ b/src/Service/Cache/Memory.php @@ -11,7 +11,7 @@ class Memory implements CacheInterface { private array $cachedItems = []; - public function get($key, $default = null) + public function get($key, $default = null): mixed { return $this->cachedItems[$key] ?? $default; }