From 98075dfeb2f13cd5ef1a173743bb08126b682295 Mon Sep 17 00:00:00 2001 From: Ivan Voskoboinyk Date: Mon, 4 Aug 2025 14:19:06 +0200 Subject: [PATCH 1/3] Raise minimum PHP version to 8.0+ --- .github/workflows/test.yml | 2 +- README.md | 3 +-- composer.json | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4a39a96..90608f0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ] + php: [ '8.0', '8.1', '8.2', '8.3', '8.4' ] steps: - uses: actions/checkout@master diff --git a/README.md b/README.md index dcdfc9a..cace7de 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,7 @@ or recursively instantiating them with *DependencyResolver* itself. ## Features - Based on PSR-11 -- Supports PHP 8 (8.0, 8.1, 8.2, 8.3 and 8.4) — full support of union type hints, and other modern features. -- PHP 7.1+ compatible +- Supports modern PHP 8 features (up to PHP 8.4) — full support of union type hints, and others. - Recursive dependencies autowiring - Semver - Tests diff --git a/composer.json b/composer.json index a9b48c1..64b61b8 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "auto-wiring" ], "require": { - "php": "^7.1|^8.0", + "php": "^8.0", "psr/container": "^1.0|^2.0", "technically/null-container": "^1.0", "technically/callable-reflection": "^0.4.0" From 067e9fbdaa18ebd2824de9569bdb5680418e595d Mon Sep 17 00:00:00 2001 From: Ivan Voskoboinyk Date: Mon, 4 Aug 2025 14:26:14 +0200 Subject: [PATCH 2/3] Update dependencies --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 64b61b8..00739ad 100644 --- a/composer.json +++ b/composer.json @@ -10,13 +10,13 @@ ], "require": { "php": "^8.0", - "psr/container": "^1.0|^2.0", - "technically/null-container": "^1.0", - "technically/callable-reflection": "^0.4.0" + "psr/container": "^2.0", + "technically/null-container": "^2.0", + "technically/callable-reflection": "^0.4.2" }, "require-dev": { "peridot-php/peridot": "^1.19", - "technically/array-container": "^1.0" + "technically/array-container": "^2.0" }, "license": "MIT", "authors": [ From 8d127628066a8638869a3303540055e9584e3903 Mon Sep 17 00:00:00 2001 From: Ivan Voskoboinyk Date: Mon, 4 Aug 2025 14:26:24 +0200 Subject: [PATCH 3/3] Upgrade code to rely on PHP8 features --- src/DependencyResolver.php | 16 +++++++--------- src/Exceptions/CannotAutowireArgument.php | 2 +- .../CannotAutowireDependencyArgument.php | 4 ++-- src/Exceptions/ClassCannotBeInstantiated.php | 6 +++--- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/DependencyResolver.php b/src/DependencyResolver.php index 87aa19d..4125d37 100644 --- a/src/DependencyResolver.php +++ b/src/DependencyResolver.php @@ -16,10 +16,7 @@ final class DependencyResolver { - /** - * @var ContainerInterface - */ - private $container; + private ContainerInterface $container; public function __construct(?ContainerInterface $container = null) { @@ -28,14 +25,14 @@ public function __construct(?ContainerInterface $container = null) /** * @param string $className - * @return mixed|object|void + * @return mixed * * @throws InvalidArgumentException If class does not exist. * @throws ContainerExceptionInterface If error occurs while retrieving the existing entry from the container. * @throws ClassCannotBeInstantiated If class cannot be instantiated. * @throws CannotAutowireDependencyArgument If a dependency (of any nesting level) cannot be resolved. */ - public function resolve(string $className) + public function resolve(string $className): mixed { if (! class_exists($className) && ! interface_exists($className)) { throw new InvalidArgumentException("`{$className}` is not a valid class name."); @@ -51,11 +48,12 @@ public function resolve(string $className) /** * @param string $className * @param array $bindings + * @return mixed * * @throws ClassCannotBeInstantiated * @throws CannotAutowireDependencyArgument */ - public function construct(string $className, array $bindings = []) + public function construct(string $className, array $bindings = []): mixed { if (! class_exists($className) && ! interface_exists($className)) { throw new InvalidArgumentException("`{$className}` is not a valid class name."); @@ -84,7 +82,7 @@ public function construct(string $className, array $bindings = []) * @throws ArgumentCountError * @throws CannotAutowireArgument */ - public function call(callable $callable, array $bindings = []) + public function call(callable $callable, array $bindings = []): mixed { $reflection = CallableReflection::fromCallable($callable); @@ -130,7 +128,7 @@ private function resolveParameters(array $parameters, array $bindings = []): arr * * @throws CannotAutowireArgument */ - private function resolveParameter(ParameterReflection $parameter) + private function resolveParameter(ParameterReflection $parameter): mixed { foreach ($parameter->getTypes() as $type) { if ($type->isClassRequirement() && $this->container->has($class = $type->getClassRequirement())) { diff --git a/src/Exceptions/CannotAutowireArgument.php b/src/Exceptions/CannotAutowireArgument.php index 7e6e673..510c340 100644 --- a/src/Exceptions/CannotAutowireArgument.php +++ b/src/Exceptions/CannotAutowireArgument.php @@ -9,7 +9,7 @@ final class CannotAutowireArgument extends DependencyResolutionException /** * @var string */ - private $argumentName; + private string $argumentName; /** * @param string $argumentName diff --git a/src/Exceptions/CannotAutowireDependencyArgument.php b/src/Exceptions/CannotAutowireDependencyArgument.php index 6ef1f85..c1af508 100644 --- a/src/Exceptions/CannotAutowireDependencyArgument.php +++ b/src/Exceptions/CannotAutowireDependencyArgument.php @@ -9,12 +9,12 @@ final class CannotAutowireDependencyArgument extends DependencyResolutionExcepti /** * @var string */ - private $dependencyName; + private string $dependencyName; /** * @var string */ - private $argumentName; + private string $argumentName; /** * @param string $dependencyName diff --git a/src/Exceptions/ClassCannotBeInstantiated.php b/src/Exceptions/ClassCannotBeInstantiated.php index 0b11c90..ab485cb 100644 --- a/src/Exceptions/ClassCannotBeInstantiated.php +++ b/src/Exceptions/ClassCannotBeInstantiated.php @@ -5,9 +5,9 @@ final class ClassCannotBeInstantiated extends DependencyResolutionException { /** - * @var string + * @var class-string */ - private $className; + private string $className; public function __construct(string $className) { @@ -17,7 +17,7 @@ public function __construct(string $className) } /** - * @return string + * @return class-string */ public function getClassName(): string {