From 791e89fdd8f27507fcf2bf3b4bba8695515633b3 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Fri, 13 Dec 2024 16:27:01 +0100 Subject: [PATCH 1/7] solve PHP 8.4 deprecation issues --- .github/workflows/test.yml | 2 +- composer.json | 2 +- src/App.php | 14 +++++++------- src/Builders/CallableBuilder.php | 4 ++-- src/Builders/ClassBuilder.php | 4 ++-- src/Builders/Factory.php | 2 +- src/Builders/ReinitializableBuilderInterface.php | 2 +- src/Builders/Resolver.php | 6 +++--- src/Container.php | 12 ++++++------ src/NestedParseError.php | 2 +- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 90fb5d76..7ae70023 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ '5.6', '7.0' , '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ] + php: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ] steps: - name: Checkout code uses: actions/checkout@v3 diff --git a/composer.json b/composer.json index d00401c2..21f9da57 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } }, "require": { - "php": ">=5.6", + "php": ">=7.1", "psr/container": "^1.0", "ext-json": "*" }, diff --git a/src/App.php b/src/App.php index 38b5ce47..ef6952a4 100644 --- a/src/App.php +++ b/src/App.php @@ -38,7 +38,7 @@ public static function container() return static::$container; } - + /** * Sets the container instance the Application should use as a Service Locator. * @@ -54,7 +54,7 @@ public static function setContainer(Container $container) { static::$container = $container; } - + /** * Sets a variable on the container. * @@ -99,7 +99,7 @@ public static function offsetSet($offset, $value) * * @throws ContainerException If there's any issue reflecting on the class, interface or the implementation. */ - public static function singleton($id, $implementation = null, array $afterBuildMethods = null) + public static function singleton($id, $implementation = null, ?array $afterBuildMethods = null) { static::container()->singleton($id, $implementation, $afterBuildMethods); } @@ -311,7 +311,7 @@ public static function register($serviceProviderClass, ...$alias) * * @throws ContainerException If there's an issue while trying to bind the implementation. */ - public static function bind($id, $implementation = null, array $afterBuildMethods = null) + public static function bind($id, $implementation = null, ?array $afterBuildMethods = null) { static::container()->bind($id, $implementation, $afterBuildMethods); } @@ -346,7 +346,7 @@ public static function boot() * @return void This method does not return any value. * @throws ContainerException */ - public static function singletonDecorators($id, $decorators, array $afterBuildMethods = null) + public static function singletonDecorators($id, $decorators, ?array $afterBuildMethods = null) { static::container()->singletonDecorators($id, $decorators, $afterBuildMethods); } @@ -367,7 +367,7 @@ public static function singletonDecorators($id, $decorators, array $afterBuildMe * @return void This method does not return any value. * @throws ContainerException If there's any issue binding the decorators. */ - public static function bindDecorators($id, array $decorators, array $afterBuildMethods = null) + public static function bindDecorators($id, array $decorators, ?array $afterBuildMethods = null) { static::container()->bindDecorators($id, $decorators, $afterBuildMethods); } @@ -480,7 +480,7 @@ public static function callback($id, $method) * @return callable A callable function that will return an instance of the specified class when * called. */ - public static function instance($id, array $buildArgs = [], array $afterBuildMethods = null) + public static function instance($id, ?array $buildArgs = [], ?array $afterBuildMethods = null) { return static::container()->instance($id, $buildArgs, $afterBuildMethods); } diff --git a/src/Builders/CallableBuilder.php b/src/Builders/CallableBuilder.php index 3d5a4cab..cce82c9b 100644 --- a/src/Builders/CallableBuilder.php +++ b/src/Builders/CallableBuilder.php @@ -53,7 +53,7 @@ class CallableBuilder implements BuilderInterface, ReinitializableBuilderInterfa public function __construct( Container $container, callable $callable, - array $afterBuildMethods = null, + ?array $afterBuildMethods = null, ...$buildArgs ) { $this->container = $container; @@ -86,7 +86,7 @@ public function build() * * @return void This method does not return any value. */ - public function reinit(array $afterBuildMethods = null, ...$buildArgs) + public function reinit(?array $afterBuildMethods = null, ...$buildArgs) { $this->afterBuildMethods = $afterBuildMethods ?: []; $this->buildArgs = $buildArgs; diff --git a/src/Builders/ClassBuilder.php b/src/Builders/ClassBuilder.php index f525c702..851f9d55 100644 --- a/src/Builders/ClassBuilder.php +++ b/src/Builders/ClassBuilder.php @@ -75,7 +75,7 @@ class ClassBuilder implements BuilderInterface, ReinitializableBuilderInterface * * @throws NotFoundException If the class does not exist. */ - public function __construct($id, Resolver $resolver, $className, array $afterBuildMethods = null, ...$buildArgs) + public function __construct($id, Resolver $resolver, $className, ?array $afterBuildMethods = null, ...$buildArgs) { if (!class_exists($className)) { throw new NotFoundException( @@ -236,7 +236,7 @@ protected function resolveParameter(Parameter $parameter) /** * {@inheritdoc} */ - public function reinit(array $afterBuildMethods = null, ...$buildArgs) + public function reinit(?array $afterBuildMethods = null, ...$buildArgs) { $this->afterBuildMethods = $afterBuildMethods; $this->buildArgs = $buildArgs; diff --git a/src/Builders/Factory.php b/src/Builders/Factory.php index 6c257732..dd4f5761 100644 --- a/src/Builders/Factory.php +++ b/src/Builders/Factory.php @@ -56,7 +56,7 @@ public function __construct(Container $container, Resolver $resolver) * * @throws NotFoundException If a builder cannot find its implementation target. */ - public function getBuilder($id, $implementation = null, array $afterBuildMethods = null, ...$buildArgs) + public function getBuilder($id, $implementation = null, ?array $afterBuildMethods = null, ...$buildArgs) { if ($implementation === null) { $implementation = $id; diff --git a/src/Builders/ReinitializableBuilderInterface.php b/src/Builders/ReinitializableBuilderInterface.php index 3d082ca1..782d80e2 100644 --- a/src/Builders/ReinitializableBuilderInterface.php +++ b/src/Builders/ReinitializableBuilderInterface.php @@ -22,5 +22,5 @@ interface ReinitializableBuilderInterface * * @return void This method does not return any value. */ - public function reinit(array $afterBuildMethods = null, ...$buildArgs); + public function reinit(?array $afterBuildMethods = null, ...$buildArgs); } diff --git a/src/Builders/Resolver.php b/src/Builders/Resolver.php index 0346e240..101205f3 100644 --- a/src/Builders/Resolver.php +++ b/src/Builders/Resolver.php @@ -170,7 +170,7 @@ public function setWhenNeedsGive($whenClass, $needsClass, BuilderInterface $buil * build arguments. * @throws NotFoundException If the id is a string that does not resolve to an existing, concrete, class. */ - public function resolveWithArgs($id, array $afterBuildMethods = null, ...$buildArgs) + public function resolveWithArgs($id, ?array $afterBuildMethods = null, ...$buildArgs) { if (! is_string($id)) { return $id; @@ -197,7 +197,7 @@ public function resolveWithArgs($id, array $afterBuildMethods = null, ...$buildA * * @throws NotFoundException If the id is a string that is not bound and is not an existing, concrete, class. */ - public function resolve($id, array $buildLine = null) + public function resolve($id, ?array $buildLine = null) { if ($buildLine !== null) { $this->buildLine = $buildLine; @@ -271,7 +271,7 @@ private function resolveBound($id) * @throws NotFoundException If trying to clone the builder for a non existing id or an id that does not map to a * concrete class name. */ - private function cloneBuilder($id, array $afterBuildMethods = null, ...$buildArgs) + private function cloneBuilder($id, ?array $afterBuildMethods = null, ...$buildArgs) { if (isset($this->bindings[$id]) && $this->bindings[$id] instanceof BuilderInterface) { $builder = clone $this->bindings[$id]; diff --git a/src/Container.php b/src/Container.php index 84f3e380..53d0e40f 100644 --- a/src/Container.php +++ b/src/Container.php @@ -148,7 +148,7 @@ public function offsetSet($offset, $value) * @return void This method does not return any value. * @throws ContainerException If there's any issue reflecting on the class, interface or the implementation. */ - public function singleton($id, $implementation = null, array $afterBuildMethods = null) + public function singleton($id, $implementation = null, ?array $afterBuildMethods = null) { if ($implementation === null) { $implementation = $id; @@ -526,7 +526,7 @@ private function getDeferredProviderMakeClosure(ServiceProvider $provider, $id) * * @throws ContainerException If there's an issue while trying to bind the implementation. */ - public function bind($id, $implementation = null, array $afterBuildMethods = null) + public function bind($id, $implementation = null, ?array $afterBuildMethods = null) { if ($implementation === null) { $implementation = $id; @@ -574,7 +574,7 @@ public function boot() * @return void This method does not return any value. * @throws ContainerException */ - public function singletonDecorators($id, $decorators, array $afterBuildMethods = null, $afterBuildAll = false) + public function singletonDecorators($id, $decorators, ?array $afterBuildMethods = null, $afterBuildAll = false) { $this->resolver->singleton( $id, @@ -600,7 +600,7 @@ public function singletonDecorators($id, $decorators, array $afterBuildMethods = private function getDecoratorBuilder( array $decorators, $id, - array $afterBuildMethods = null, + ?array $afterBuildMethods = null, $afterBuildAll = false ) { $decorator = array_pop($decorators); @@ -639,7 +639,7 @@ private function getDecoratorBuilder( * @return void This method does not return any value. * @throws ContainerException If there's any issue binding the decorators. */ - public function bindDecorators($id, array $decorators, array $afterBuildMethods = null, $afterBuildAll = false) + public function bindDecorators($id, array $decorators, ?array $afterBuildMethods = null, $afterBuildAll = false) { $this->resolver->bind($id, $this->getDecoratorBuilder($decorators, $id, $afterBuildMethods, $afterBuildAll)); } @@ -818,7 +818,7 @@ protected function isStaticMethod($object, $method) * @return callable|Closure A callable function that will return an instance of the specified class when * called. */ - public function instance($id, array $buildArgs = [], array $afterBuildMethods = null) + public function instance($id, array $buildArgs = [], ?array $afterBuildMethods = null) { return function () use ($id, $afterBuildMethods, $buildArgs) { if (is_string($id)) { diff --git a/src/NestedParseError.php b/src/NestedParseError.php index 8e8853a0..d9deae87 100644 --- a/src/NestedParseError.php +++ b/src/NestedParseError.php @@ -40,7 +40,7 @@ class NestedParseError extends \Exception * @param string $type The type of the entity being loaded. * @param string $name The name of the entity being loaded. */ - public function __construct($message = "", $code = 0, Throwable $previous = null, $type = '', $name = '') + public function __construct($message = "", $code = 0, ?Throwable $previous = null, $type = '', $name = '') { parent::__construct($message, $code, $previous); $this->type = $type; From 525e4d6c40421126a64ee52ad8037733e1323da9 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Fri, 13 Dec 2024 16:59:14 +0100 Subject: [PATCH 2/7] build(.github) update qa workflow to use php 7.1 min --- .github/workflows/qa.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index d1b1f495..7810fd7c 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -7,38 +7,38 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 - - name: Setup PHP 5.6 + - name: Setup PHP 7.1 uses: shivammathur/setup-php@v2 with: - php-version: 5.6 + php-version: 7.1 - name: Install dependencies uses: "ramsey/composer-install@v2" - name: Run phpcs run: make phpcs phpstan: - name: phpstan on PHP 5.6 + name: phpstan on PHP 7.1 runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - - name: Setup PHP 5.6 + - name: Setup PHP 7.1 uses: shivammathur/setup-php@v2 with: - php-version: 5.6 + php-version: 7.1 - name: Install dependencies uses: "ramsey/composer-install@v2" - name: Run phpstan run: make phpstan phan: - name: phan on PHP 5.6 + name: phan on PHP 7.1 runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - - name: Setup PHP 5.6 + - name: Setup PHP 7.1 uses: shivammathur/setup-php@v2 with: - php-version: 5.6 + php-version: 7.1 - name: Install dependencies uses: "ramsey/composer-install@v2" - name: Run phan From d68e8f60428f3901b0a3dd4af2f843ea14d45aec Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Sat, 14 Dec 2024 11:44:07 +0100 Subject: [PATCH 3/7] fix(src) phpstan flagged issues --- composer.json | 5 +++++ src/App.php | 2 +- src/Container.php | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 21f9da57..2690f7d5 100644 --- a/composer.json +++ b/composer.json @@ -20,5 +20,10 @@ }, "require-dev": { "phpunit/phpunit": "<10.0" + }, + "config": { + "platform": { + "php": "7.1" + } } } diff --git a/src/App.php b/src/App.php index ef6952a4..66985d00 100644 --- a/src/App.php +++ b/src/App.php @@ -482,7 +482,7 @@ public static function callback($id, $method) */ public static function instance($id, ?array $buildArgs = [], ?array $afterBuildMethods = null) { - return static::container()->instance($id, $buildArgs, $afterBuildMethods); + return static::container()->instance($id, $buildArgs ?? [], $afterBuildMethods); } /** diff --git a/src/Container.php b/src/Container.php index 53d0e40f..4fc2f75d 100644 --- a/src/Container.php +++ b/src/Container.php @@ -459,6 +459,7 @@ public function register($serviceProviderClass, ...$alias) $provider->register(); } else { $provided = $provider->provides(); + // @phpstan-ignore-next-line if (!is_array($provided) || count($provided) === 0) { throw new ContainerException( "Service provider '{$serviceProviderClass}' is marked as deferred" . @@ -748,6 +749,7 @@ public function callback($id, $method) { $callbackIdPrefix = is_object($id) ? spl_object_hash($id) : $id; + // @phpstan-ignore-next-line if (!is_string($callbackIdPrefix)) { $typeOfId = gettype($id); throw new ContainerException( @@ -755,6 +757,7 @@ public function callback($id, $method) ); } + // @phpstan-ignore-next-line if (!is_string($method)) { throw new ContainerException("Callbacks second argument must be a string method name."); } @@ -878,6 +881,7 @@ public function getProvider($providerId) */ public function isBound($id) { + // @phpstan-ignore-next-line return is_string($id) && $this->resolver->isBound($id); } From 43eb3d6c6ae231ba5749a7c327be08f8603ffa1c Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Sat, 14 Dec 2024 11:47:44 +0100 Subject: [PATCH 4/7] build(phan) update config file --- config/phan-config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/phan-config.php b/config/phan-config.php index c9442b0f..41c8fda6 100644 --- a/config/phan-config.php +++ b/config/phan-config.php @@ -43,7 +43,7 @@ // Note that the **only** effect of choosing `'5.6'` is to infer that functions removed in php 7.0 exist. // (See `backward_compatibility_checks` for additional options) // Automatically inferred from composer.json requirement for "php" of ">=5.6" - 'target_php_version' => '5.6', + 'target_php_version' => '7.1', // If enabled, missing properties will be created when // they are first seen. If false, we'll report an From 24d9e63e58c5e3f9b657fddec5f183b19ebf66fc Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Sat, 14 Dec 2024 11:47:54 +0100 Subject: [PATCH 5/7] fix(src) phan issues --- src/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.php b/src/App.php index 66985d00..e72b2b95 100644 --- a/src/App.php +++ b/src/App.php @@ -471,7 +471,7 @@ public static function callback($id, $method) * The callable will be a closure on PHP 5.3+ or a lambda function on PHP 5.2. * * @param string|class-string|mixed $id The fully qualified name of a class or an interface. - * @param array $buildArgs An array of arguments that should be used to build the + * @param array|null $buildArgs An array of arguments that should be used to build the * instance; note that any argument will be resolved using * the container itself and bindings will apply. * @param string[]|null $afterBuildMethods An array of methods that should be called on the built From a91fc4f6e50935c3b09d5e545b4939b476fab930 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Sat, 14 Dec 2024 11:48:16 +0100 Subject: [PATCH 6/7] doc(CHANGELOG.md) update with entry --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cc8a826..e08e2e93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ to [Semantic Versioning](http://semver.org/). ## [unreleased] Unreleased +### Changed + +- Bumped minimum supported version to PHP 7.1. +- Fixed PHP 8.4 deprecation warnings. + ## [3.3.7] 2024-04-26; ### Fixed From d1aec798fe06c180897d04f280d0bff199354adf Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Sat, 14 Dec 2024 11:49:31 +0100 Subject: [PATCH 7/7] build(composer.json) remove platform entry --- composer.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/composer.json b/composer.json index 2690f7d5..21f9da57 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,5 @@ }, "require-dev": { "phpunit/phpunit": "<10.0" - }, - "config": { - "platform": { - "php": "7.1" - } } }