diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81f1f2f..c7f2d07 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 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index aadabde..c6ad76f 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 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 diff --git a/composer.json b/composer.json index 7c9fc6b..6f03b62 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,10 @@ "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" + "psr/simple-cache": "^1.0 | ^2.0 | ^3.0" }, "autoload": { "psr-4": { 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..e21f78e 100644 --- a/src/Injection/AutoWiringPluginManager.php +++ b/src/Injection/AutoWiringPluginManager.php @@ -26,21 +26,20 @@ 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 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; } 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]);