From f5a8cdb5130f0812f694917fd41549401e02a5ee Mon Sep 17 00:00:00 2001 From: heinrichschiller Date: Wed, 20 Aug 2025 08:40:54 +0200 Subject: [PATCH 01/11] Add PHP 8.4 support --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1c3c3cb..2f9eee3 100644 --- a/composer.json +++ b/composer.json @@ -7,12 +7,12 @@ "psr-11" ], "require": { - "php": "^8.1", + "php": "8.1.* || 8.2.* || 8.3.* || 8.4.*", "psr/container": "^2.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3", - "phpstan/phpstan": "^1", + "phpstan/phpstan": "^2", "phpunit/phpunit": "^10", "squizlabs/php_codesniffer": "^3", "symfony/event-dispatcher": "^5 || 6.0.*" From 4414a51a3a71ad405c5e71d97458a59afd6ec2d4 Mon Sep 17 00:00:00 2001 From: heinrichschiller Date: Wed, 20 Aug 2025 08:43:04 +0200 Subject: [PATCH 02/11] fixed compact_nullable_typehint deprecation --- .cs.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.cs.php b/.cs.php index 2bba5e9..52c4c3e 100644 --- a/.cs.php +++ b/.cs.php @@ -19,7 +19,7 @@ 'array_syntax' => ['syntax' => 'short'], 'cast_spaces' => ['space' => 'none'], 'concat_space' => ['spacing' => 'one'], - 'compact_nullable_typehint' => true, + 'compact_nullable_type_declaration' => true, 'declare_equal_normalize' => ['space' => 'single'], 'general_phpdoc_annotation_remove' => [ 'annotations' => [ @@ -36,7 +36,11 @@ 'phpdoc_order' => true, // psr-5 'phpdoc_no_useless_inheritdoc' => false, 'protected_to_private' => false, - 'yoda_style' => false, + 'yoda_style' => [ + 'equal' => false, + 'identical' => false, + 'less_and_greater' => false + ], 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], 'ordered_imports' => [ 'sort_algorithm' => 'alpha', From 8f196ae90bf0588a14bffa60fa59678e12e92f3e Mon Sep 17 00:00:00 2001 From: heinrichschiller Date: Wed, 20 Aug 2025 08:45:50 +0200 Subject: [PATCH 03/11] Fix nullable types for PHP 8.4 --- src/Exceptions/InvalidDefinitionException.php | 2 +- src/Resolver/ConstructorResolver.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Exceptions/InvalidDefinitionException.php b/src/Exceptions/InvalidDefinitionException.php index 69202ea..25a1364 100644 --- a/src/Exceptions/InvalidDefinitionException.php +++ b/src/Exceptions/InvalidDefinitionException.php @@ -19,7 +19,7 @@ class InvalidDefinitionException extends Exception implements ContainerException * * @return self */ - public static function create(string $message, Throwable $previous = null): self + public static function create(string $message, ?Throwable $previous = null): self { return new self($message, 0, $previous); } diff --git a/src/Resolver/ConstructorResolver.php b/src/Resolver/ConstructorResolver.php index 81ad25e..2ffa762 100644 --- a/src/Resolver/ConstructorResolver.php +++ b/src/Resolver/ConstructorResolver.php @@ -78,7 +78,7 @@ public function resolve(string $id) * * @return array The resolved parameters */ - private function resolveParameters(string $id, ReflectionMethod $method = null): array + private function resolveParameters(string $id, ?ReflectionMethod $method = null): array { if ($method === null) { return []; From c56f51e3865367f34a47061712f5ccd8ea3dbbcf Mon Sep 17 00:00:00 2001 From: heinrichschiller Date: Wed, 20 Aug 2025 08:52:53 +0200 Subject: [PATCH 04/11] update readme --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4e9451d..0878f4f 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ [![Latest Version on Packagist](https://img.shields.io/github/release/selective-php/container.svg)](https://packagist.org/packages/selective/container) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) [![Build Status](https://github.com/selective-php/container/workflows/build/badge.svg)](https://github.com/selective-php/container/actions) -[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/selective-php/container.svg)](https://scrutinizer-ci.com/g/selective-php/container/code-structure) -[![Quality Score](https://img.shields.io/scrutinizer/quality/g/selective-php/container.svg)](https://scrutinizer-ci.com/g/selective-php/container/?branch=master) [![Total Downloads](https://img.shields.io/packagist/dt/selective/container.svg)](https://packagist.org/packages/selective/container/stats) ## Description @@ -13,11 +11,11 @@ A PSR-11 container implementation with optional **autowiring**. ## Requirements - * PHP 8.1+ + * PHP 8.1 - 8.4 ## Installation -``` +```bash composer require selective/container ``` From 36d76d4a7486ca98e57a816fc7feb5a4cfefbdee Mon Sep 17 00:00:00 2001 From: heinrichschiller Date: Wed, 20 Aug 2025 08:53:27 +0200 Subject: [PATCH 05/11] update year --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index bf7a9a3..bfcf021 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2023 odan +Copyright (c) 2025 odan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 279f700d2328b9abfce3ec0bbc43b61f656effbd Mon Sep 17 00:00:00 2001 From: heinrichschiller Date: Wed, 20 Aug 2025 08:57:27 +0200 Subject: [PATCH 06/11] fixed PHP_CS_FIXER_IGNORE_ENV deprecation --- composer.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 2f9eee3..24efd4a 100644 --- a/composer.json +++ b/composer.json @@ -32,12 +32,10 @@ }, "scripts": { "cs:check": [ - "@putenv PHP_CS_FIXER_IGNORE_ENV=1", - "php-cs-fixer fix --dry-run --format=txt --verbose --diff --config=.cs.php --ansi" + "php-cs-fixer fix --dry-run --format=txt --verbose --diff --config=.cs.php --ansi --allow-unsupported-php-version=yes" ], "cs:fix": [ - "@putenv PHP_CS_FIXER_IGNORE_ENV=1", - "php-cs-fixer fix --config=.cs.php --ansi --verbose" + "php-cs-fixer fix --config=.cs.php --ansi --verbose --allow-unsupported-php-version=yes" ], "sniffer:check": "phpcs --standard=phpcs.xml", "sniffer:fix": "phpcbf --standard=phpcs.xml", From a1d98ba9ce611b73185c8fc02dd42079d61a16a3 Mon Sep 17 00:00:00 2001 From: heinrichschiller Date: Wed, 20 Aug 2025 09:02:00 +0200 Subject: [PATCH 07/11] update composer test:coverage script --- composer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 24efd4a..25c0282 100644 --- a/composer.json +++ b/composer.json @@ -47,6 +47,9 @@ "@stan", "@test" ], - "test:coverage": "php -d xdebug.mode=coverage -r \"require 'vendor/bin/phpunit';\" -- --configuration phpunit.xml --do-not-cache-result --colors=always --coverage-clover build/logs/clover.xml --coverage-html build/coverage" + "test:coverage": [ + "@putenv XDEBUG_MODE=coverage", + "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --display-warnings --display-deprecations --coverage-clover build/coverage/clover.xml --coverage-html build/coverage --coverage-text" + ] } } From 33d2eeea9b2700ccf3d868f7a528f1195c2f10d7 Mon Sep 17 00:00:00 2001 From: heinrichschiller Date: Wed, 20 Aug 2025 10:19:30 +0200 Subject: [PATCH 08/11] removed PHP 7 code --- tests/TestCase/ContainerTest.php | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/tests/TestCase/ContainerTest.php b/tests/TestCase/ContainerTest.php index 6c9801a..45fbf8f 100644 --- a/tests/TestCase/ContainerTest.php +++ b/tests/TestCase/ContainerTest.php @@ -290,16 +290,7 @@ public function testAutowireWithInvalidInternalClass(): void $container = new Container(); $container->addResolver(new ConstructorResolver($container)); - // https://3v4l.org/1AXpr - if (version_compare(PHP_VERSION, '8.0.0') >= 0) { - // PHP 8+ - $this->assertInstanceOf(Exception::class, $container->get(Exception::class)); - } else { - // PHP 7.x - // Cannot determine default value for internal functions - $this->expectException(InvalidDefinitionException::class); - $container->get(Exception::class); - } + $this->assertInstanceOf(Exception::class, $container->get(Exception::class)); } /** @@ -312,15 +303,7 @@ public function testAutowireWithInvalidInternalInterface(): void $container = new Container(); $container->addResolver(new ConstructorResolver($container)); - if (version_compare(PHP_VERSION, '8.0.0') >= 0) { - // PHP 8+ - $this->assertInstanceOf(NotFoundException::class, $container->get(NotFoundException::class)); - } else { - // PHP 7.x - // Cannot determine default value for internal functions - $this->expectException(InvalidDefinitionException::class); - $container->get(NotFoundException::class); - } + $this->assertInstanceOf(NotFoundException::class, $container->get(NotFoundException::class)); } /** From f38336f2c386bcb2b467eea7fbfb339d0332e1e8 Mon Sep 17 00:00:00 2001 From: heinrichschiller Date: Thu, 21 Aug 2025 08:55:01 +0200 Subject: [PATCH 09/11] added autowire returns null test --- tests/TestCase/ContainerTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/TestCase/ContainerTest.php b/tests/TestCase/ContainerTest.php index 45fbf8f..f63e52c 100644 --- a/tests/TestCase/ContainerTest.php +++ b/tests/TestCase/ContainerTest.php @@ -12,6 +12,7 @@ use Selective\Container\Exceptions\InvalidDefinitionException; use Selective\Container\Exceptions\NotFoundException; use Selective\Container\Resolver\ConstructorResolver; +use Selective\Container\Resolver\DefinitionResolverInterface; use Selective\Container\Test\TestCase\Service\MyAbstractService; use Selective\Container\Test\TestCase\Service\MyService; use Selective\Container\Test\TestCase\Service\MyServiceA; @@ -336,4 +337,25 @@ public function testAutowireWithNotExistingClass(): void $container->addResolver(new ConstructorResolver($container)); $container->get('Nada\Foo'); } + + /** + * Test. + * + * @return void + */ + public function testAutowireReturnsNull(): void + { + $container = new Container(); + + $resolver = $this->createMock(DefinitionResolverInterface::class); + $resolver->method('isResolvable')->willReturn(false); + $resolver->expects($this->once()) + ->method('resolve') + ->with(stdClass::class) + ->willReturn(null); + + $container->addResolver($resolver); + + $this->assertNull($container->get(stdClass::class)); + } } From 56c3f55a1975acd9444b92ec5a39bde6a315d814 Mon Sep 17 00:00:00 2001 From: heinrichschiller Date: Thu, 21 Aug 2025 09:05:59 +0200 Subject: [PATCH 10/11] added resolveparameters return empty array when method is null test --- .../Resolver/ConstructorResolverTest.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/TestCase/Resolver/ConstructorResolverTest.php b/tests/TestCase/Resolver/ConstructorResolverTest.php index 33279a9..bfd55a1 100644 --- a/tests/TestCase/Resolver/ConstructorResolverTest.php +++ b/tests/TestCase/Resolver/ConstructorResolverTest.php @@ -6,9 +6,16 @@ use Selective\Container\Container; use Selective\Container\Exceptions\InvalidDefinitionException; use Selective\Container\Resolver\ConstructorResolver; +use ReflectionMethod; +use stdClass; final class ConstructorResolverTest extends TestCase { + /** + * Test. + * + * @return void + */ public function testResolveOnInvalidDefinition(): void { $this->expectException(InvalidDefinitionException::class); @@ -19,4 +26,25 @@ public function testResolveOnInvalidDefinition(): void $constructorResolver = new ConstructorResolver($container); $constructorResolver->resolve($invalidId); } + + /** + * Resolve parameters returns empty array when method is null. + * + * @return void + */ + public function testResolveParametersReturnsEmptyArrayWhenMethodIsNull(): void + { + $container = new Container(); + $resolver = new ConstructorResolver($container); + + $ref = new ReflectionMethod( + ConstructorResolver::class, + 'resolveParameters' + ); + $ref->setAccessible(true); + + $result = $ref->invoke($resolver, stdClass::class, null); + + $this->assertSame([], $result); + } } From d6e62027c422fd8327b42ec1a7950ae5b652c0fa Mon Sep 17 00:00:00 2001 From: heinrichschiller Date: Thu, 21 Aug 2025 09:13:59 +0200 Subject: [PATCH 11/11] cs and sniffer fix --- tests/TestCase/Resolver/ConstructorResolverTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/TestCase/Resolver/ConstructorResolverTest.php b/tests/TestCase/Resolver/ConstructorResolverTest.php index bfd55a1..f6a3fd4 100644 --- a/tests/TestCase/Resolver/ConstructorResolverTest.php +++ b/tests/TestCase/Resolver/ConstructorResolverTest.php @@ -3,17 +3,17 @@ namespace Selective\Container\Test\Resolver\TestCase; use PHPUnit\Framework\TestCase; +use ReflectionMethod; use Selective\Container\Container; use Selective\Container\Exceptions\InvalidDefinitionException; use Selective\Container\Resolver\ConstructorResolver; -use ReflectionMethod; use stdClass; final class ConstructorResolverTest extends TestCase { /** * Test. - * + * * @return void */ public function testResolveOnInvalidDefinition(): void @@ -29,7 +29,7 @@ public function testResolveOnInvalidDefinition(): void /** * Resolve parameters returns empty array when method is null. - * + * * @return void */ public function testResolveParametersReturnsEmptyArrayWhenMethodIsNull(): void