From 78cd199f0036f0dfaedb16ee4a1d79b89b20d2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Wed, 14 Jan 2026 15:42:46 +0400 Subject: [PATCH 1/4] configs + deps --- .github/workflows/rector-cs.yml | 27 +++++++++++ .github/workflows/rector.yml | 24 ---------- .gitignore | 4 +- .php-cs-fixer.dist.php | 42 ++++++++++++++++ .styleci.yml | 85 --------------------------------- composer.json | 1 + 6 files changed, 73 insertions(+), 110 deletions(-) create mode 100644 .github/workflows/rector-cs.yml delete mode 100644 .github/workflows/rector.yml create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .styleci.yml diff --git a/.github/workflows/rector-cs.yml b/.github/workflows/rector-cs.yml new file mode 100644 index 00000000..23513499 --- /dev/null +++ b/.github/workflows/rector-cs.yml @@ -0,0 +1,27 @@ +name: Rector + PHP CS Fixer + +on: + pull_request_target: + paths: + - 'src/**' + - 'tests/**' + - '.github/workflows/rector-cs.yml' + - 'composer.json' + - 'rector.php' + - '.php-cs-fixer.dist.php' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rector: + uses: yiisoft/actions/.github/workflows/rector-cs.yml@master + secrets: + token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + php: '8.0' diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml deleted file mode 100644 index 20f7d899..00000000 --- a/.github/workflows/rector.yml +++ /dev/null @@ -1,24 +0,0 @@ -on: - pull_request_target: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' - -name: rector - -jobs: - rector: - uses: yiisoft/actions/.github/workflows/rector.yml@master - secrets: - token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - os: >- - ['ubuntu-latest'] - php: >- - ['8.5'] diff --git a/.gitignore b/.gitignore index 12846969..272c008b 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,6 @@ phpunit.phar # phpunit cache .phpunit.result.cache - +# PHP CS Fixer +/.php-cs-fixer.cache +/.php-cs-fixer.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..2d5d3766 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,42 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', +])->notPath([ + 'MockHelper.php' +]); + +// TODO: Update the configuration after raising the minimum PHP version +return (new Config()) + ->setRiskyAllowed(true) + ->setParallelConfig(ParallelConfigFactory::detect()) + ->setRules([ + '@PER-CS2.0' => true, + 'nullable_type_declaration' => true, + 'operator_linebreak' => true, + 'ordered_types' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], + 'single_class_element_per_statement' => true, + 'types_spaces' => true, + 'no_unused_imports' => true, + 'ordered_class_elements' => true, + 'class_attributes_separation' => ['elements' => ['method' => 'one']], + 'declare_strict_types' => true, + 'native_function_invocation' => true, + 'native_constant_invocation' => true, + 'fully_qualified_strict_types' => [ + 'import_symbols' => true + ], + 'global_namespace_import' => [ + 'import_classes' => true, + 'import_constants' => true, + 'import_functions' => true, + ], + ]) + ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index e1210398..00000000 --- a/.styleci.yml +++ /dev/null @@ -1,85 +0,0 @@ -preset: psr12 -risky: true - -version: 8.2 - -finder: - exclude: - - docs - - vendor - -enabled: - - alpha_ordered_traits - - array_indentation - - array_push - - combine_consecutive_issets - - combine_consecutive_unsets - - combine_nested_dirname - - declare_strict_types - - dir_constant - - fully_qualified_strict_types - - function_to_constant - - hash_to_slash_comment - - is_null - - logical_operators - - magic_constant_casing - - magic_method_casing - - method_separation - - modernize_types_casting - - native_function_casing - - native_function_type_declaration_casing - - no_alias_functions - - no_empty_comment - - no_empty_phpdoc - - no_empty_statement - - no_extra_block_blank_lines - - no_short_bool_cast - - no_superfluous_elseif - - no_unneeded_control_parentheses - - no_unneeded_curly_braces - - no_unneeded_final_method - - no_unset_cast - - no_unused_imports - - no_unused_lambda_imports - - no_useless_else - - no_useless_return - - normalize_index_brace - - php_unit_dedicate_assert - - php_unit_dedicate_assert_internal_type - - php_unit_expectation - - php_unit_mock - - php_unit_mock_short_will_return - - php_unit_namespaced - - php_unit_no_expectation_annotation - - phpdoc_no_empty_return - - phpdoc_no_useless_inheritdoc - - phpdoc_order - - phpdoc_property - - phpdoc_scalar - - phpdoc_singular_inheritdoc - - phpdoc_trim - - phpdoc_trim_consecutive_blank_line_separation - - phpdoc_type_to_var - - phpdoc_types - - phpdoc_types_order - - print_to_echo - - regular_callable_call - - return_assignment - - self_accessor - - self_static_accessor - - set_type_to_cast - - short_array_syntax - - short_list_syntax - - simplified_if_return - - single_quote - - standardize_not_equals - - ternary_to_null_coalescing - - trailing_comma_in_multiline_array - - unalign_double_arrow - - unalign_equals - - empty_loop_body_braces - - integer_literal_case - - union_type_without_spaces - -disabled: - - function_declaration diff --git a/composer.json b/composer.json index a633b777..362dcd20 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,7 @@ }, "require-dev": { "bamarni/composer-bin-plugin": "^1.8.3", + "friendsofphp/php-cs-fixer": "^3.66", "maglnet/composer-require-checker": "^4.4", "phpunit/phpunit": "^9.6.22", "rector/rector": "^2.0.10", From 4ce93dbb87c46c2f885cc0388deeec0330390ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Wed, 14 Jan 2026 15:43:46 +0400 Subject: [PATCH 2/4] fix CS --- src/Factory.php | 34 ++--- src/FactoryInternalContainer.php | 16 +- src/NotFoundException.php | 4 +- src/StrictFactory.php | 2 +- tests/FactoryCircularReferencesTest.php | 6 +- tests/FactoryTest.php | 144 +++++++++--------- tests/Support/Car.php | 4 +- tests/Support/Circular/Chicken.php | 4 +- tests/Support/Circular/CircularA.php | 4 +- tests/Support/Circular/CircularB.php | 4 +- tests/Support/Circular/Egg.php | 4 +- tests/Support/Circular/TreeItem.php | 4 +- tests/Support/Cube.php | 4 +- tests/Support/EngineMarkOne.php | 4 +- tests/Support/Firefighter.php | 4 +- tests/Support/GearBox.php | 4 +- tests/Support/NullableConcreteDependency.php | 4 +- tests/Support/NullableInterfaceDependency.php | 4 +- .../NullableOptionalConcreteDependency.php | 4 +- .../NullableOptionalInterfaceDependency.php | 4 +- .../NullableScalarConstructorArgument.php | 4 +- tests/Support/Phone.php | 5 +- tests/Support/PinkCircle.php | 4 +- tests/Support/ScalarConstructorArgument.php | 4 +- tests/Support/TwoParametersDependency.php | 4 +- tests/Support/UnionBuiltInTypes.php | 4 +- 26 files changed, 125 insertions(+), 162 deletions(-) diff --git a/src/Factory.php b/src/Factory.php index 898f8560..53df5997 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -34,7 +34,7 @@ final class Factory public function __construct( ?ContainerInterface $container = null, array $definitions = [], - private bool $validate = true + private bool $validate = true, ) { $this->validateDefinitions($definitions); $this->internalContainer = new FactoryInternalContainer($container, $definitions); @@ -54,21 +54,6 @@ public function withDefinitions(array $definitions): self return $new; } - /** - * @param array $definitions Definitions to validate. - * @psalm-param array $definitions - * - * @throws InvalidConfigException - */ - private function validateDefinitions(array $definitions): void - { - if ($this->validate) { - foreach ($definitions as $id => $definition) { - DefinitionValidator::validate($definition, $id); - } - } - } - /** * Creates a new object using the given configuration. * @@ -140,6 +125,21 @@ public function create(mixed $config): mixed return $this->internalContainer->create($definition); } + /** + * @param array $definitions Definitions to validate. + * @psalm-param array $definitions + * + * @throws InvalidConfigException + */ + private function validateDefinitions(array $definitions): void + { + if ($this->validate) { + foreach ($definitions as $id => $definition) { + DefinitionValidator::validate($definition, $id); + } + } + } + /** * @throws InvalidConfigException */ @@ -155,7 +155,7 @@ private function createDefinition(mixed $config): DefinitionInterface ) { $definition = $this->mergeDefinitions( $containerDefinition, - $definition + $definition, ); } diff --git a/src/FactoryInternalContainer.php b/src/FactoryInternalContainer.php index 1057e54d..61e78c0c 100644 --- a/src/FactoryInternalContainer.php +++ b/src/FactoryInternalContainer.php @@ -18,6 +18,7 @@ use function array_key_exists; use function is_object; use function is_string; +use function sprintf; /** * Factory's primary container. @@ -42,9 +43,8 @@ final class FactoryInternalContainer implements ContainerInterface */ public function __construct( private ?ContainerInterface $container, - private array $definitions - ) { - } + private array $definitions, + ) {} /** * @param array $definitions Definitions to create objects with. @@ -117,14 +117,14 @@ public function getDefinition(string $id): DefinitionInterface ) { $this->definitionInstances[$id] = $this->getDefinition($this->definitions[$id]); } else { - $this->definitionInstances[$id] = - (is_string($this->definitions[$id]) && class_exists($this->definitions[$id])) + $this->definitionInstances[$id] + = (is_string($this->definitions[$id]) && class_exists($this->definitions[$id])) ? ArrayDefinition::fromPreparedData($this->definitions[$id]) : Normalizer::normalize($this->definitions[$id], $id); } } else { throw new LogicException( - sprintf('No definition found for "%s".', $id) + sprintf('No definition found for "%s".', $id), ); } } @@ -157,8 +157,8 @@ private function build(string $id): mixed sprintf( 'Circular reference to "%s" detected while creating: %s.', $id, - implode(', ', array_keys($this->creatingIds)) - ) + implode(', ', array_keys($this->creatingIds)), + ), ); } diff --git a/src/NotFoundException.php b/src/NotFoundException.php index 3bdb8845..c631797a 100644 --- a/src/NotFoundException.php +++ b/src/NotFoundException.php @@ -7,6 +7,8 @@ use Exception; use Psr\Container\NotFoundExceptionInterface; +use function sprintf; + /** * NotFoundException is thrown when no definition or class was found in the factory for a given ID. */ @@ -16,7 +18,7 @@ final class NotFoundException extends Exception implements NotFoundExceptionInte * @param string $id ID of the definition or name of the class that was not found. */ public function __construct( - private string $id + private string $id, ) { parent::__construct(sprintf('No definition or class found or resolvable for %s.', $id)); } diff --git a/src/StrictFactory.php b/src/StrictFactory.php index c8300353..a7f875fc 100644 --- a/src/StrictFactory.php +++ b/src/StrictFactory.php @@ -55,7 +55,7 @@ public function create(string $id): mixed } return $this->internalContainer->create( - $this->internalContainer->getDefinition($id) + $this->internalContainer->getDefinition($id), ); } diff --git a/tests/FactoryCircularReferencesTest.php b/tests/FactoryCircularReferencesTest.php index 9c020606..f09e4bb3 100644 --- a/tests/FactoryCircularReferencesTest.php +++ b/tests/FactoryCircularReferencesTest.php @@ -37,7 +37,7 @@ public function testCircularClassDependency(): void [ Chicken::class => Chicken::class, Egg::class => Egg::class, - ] + ], ); $this->expectException(CircularReferenceException::class); @@ -63,12 +63,12 @@ public function testCircularReferences(): void 'engine-1' => Reference::to('engine-2'), 'engine-2' => Reference::to('engine-3'), 'engine-3' => Reference::to('engine-1'), - ] + ], ); $this->expectException(CircularReferenceException::class); $this->expectExceptionMessage( - 'Circular reference to "engine-2" detected while creating: engine-2, engine-3, engine-1.' + 'Circular reference to "engine-2" detected while creating: engine-2, engine-3, engine-1.', ); $factory->create('engine-1'); } diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 68f650f5..62c30a6b 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -265,7 +265,7 @@ public function testCreateWithCallableParametersInConstructor(): void $object = $factory->create([ 'class' => CallableDependency::class, '__construct()' => [ - 'callback' => static fn () => 42, + 'callback' => static fn() => 42, ], ]); @@ -349,7 +349,7 @@ public function testDoNotFallbackToContainerForReference(): void [ EngineInterface::class => new EngineMarkTwo(), 'engine' => Reference::to(EngineInterface::class), - ] + ], ); $engine = $factory->create('engine'); @@ -369,7 +369,7 @@ public function testDoNotFallbackToContainerForReferenceInConstructorOfArrayDefi Reference::to(EngineInterface::class), ], ], - ] + ], ); $car = $factory->create(Car::class); @@ -384,7 +384,7 @@ public function testDoNotFallbackToContainerForReferenceInConstructorOfArrayDefi ]), [ EngineInterface::class => new EngineMarkTwo(), - ] + ], ); $car = $factory->create([ @@ -410,7 +410,7 @@ public function testDoNotFallbackToContainerForReferenceInMethodOfArrayDefinitio Reference::to(ColorInterface::class), ], ], - ] + ], ); $car = $factory->create(Car::class); @@ -426,7 +426,7 @@ public function testDoNotFallbackToContainerForReferenceInMethodOfArrayDefinitio ]), [ ColorInterface::class => new ColorPink(), - ] + ], ); $car = $factory->create([ @@ -446,7 +446,7 @@ public function testFallbackToContainerForReference(): void ]), [ 'engine' => Reference::to(EngineInterface::class), - ] + ], ); $this->assertInstanceOf(EngineMarkOne::class, $factory->create('engine')); @@ -555,7 +555,7 @@ public function testCreate( $expectedName, $expectedVersion, $factoryDefinition, - $createDefinition + $createDefinition, ): void { $factory = new Factory(new SimpleContainer(), [ Phone::class => $factoryDefinition, @@ -571,8 +571,8 @@ public function testCreate( public function dataCreateObjectWithVariadicClosuresInConstructor(): array { return [ - [[fn () => '1'], '1'], - [[fn () => '1', fn () => '2'], '12'], + [[fn() => '1'], '1'], + [[fn() => '1', fn() => '2'], '12'], [[], ''], ]; } @@ -646,7 +646,7 @@ public function testDefinitionInConstructor(): void $this->expectException(InvalidConfigException::class); $this->expectExceptionMessageMatches( - '/^Only references are allowed in constructor arguments, a definition object was provided:/' + '/^Only references are allowed in constructor arguments, a definition object was provided:/', ); $factory->create([ 'class' => Car::class, @@ -662,8 +662,8 @@ public function testDefinitionAsConstructorArgument(): void $this->expectException(InvalidConfigException::class); $this->expectExceptionMessageMatches( - '~^Only references are allowed in constructor arguments, a definition object was provided: ' . - '(\\\\|)Yiisoft\\\\Definitions\\\\ArrayDefinition::~' + '~^Only references are allowed in constructor arguments, a definition object was provided: ' + . '(\\\\|)Yiisoft\\\\Definitions\\\\ArrayDefinition::~', ); $factory->create([ 'class' => Cube::class, @@ -718,7 +718,7 @@ public function testShouldNotCreateUnspecifiedInterface(): void $factory = new Factory( new SimpleContainer([ ContainerInterface::class => new SimpleContainer(), - ]) + ]), ); $this->expectException(NotFoundException::class); @@ -733,7 +733,7 @@ public function testCreateObjectWithDefinitionAndContainer(): void ]), [ EngineInterface::class => new EngineMarkTwo(), - ] + ], ); $engine = $factory->create(EngineInterface::class); @@ -751,7 +751,7 @@ public function testDefinitionEqualId(): void 'class' => EngineMarkOne::class, '__construct()' => [42], ], - ] + ], ); /** @var EngineMarkOne $engine */ @@ -827,7 +827,7 @@ public function testIntegerIndexedConstructorArguments(): void ArrayIterator::STD_PROP_LIST, ], ], - ] + ], ); $items = $factory->create('items'); @@ -848,7 +848,7 @@ public function testExcessiveConstructorParametersIgnored(): void 'age' => 43, ], ], - ] + ], ); $object = $factory->create('test'); @@ -882,7 +882,7 @@ public function testVariadicConstructorStringIndexedParameters(): void 'parameters' => [42, 43, 44], ], ], - ] + ], ); $object = $factory->create('test'); @@ -908,7 +908,7 @@ public function testVariadicConstructorIntegerIndexedParameters(): void 44, ], ], - ] + ], ); $object = $factory->create('test'); @@ -975,7 +975,7 @@ public function testDynamicReferenceInConstructor(): void public function testClosureInProperty(): void { - $color = static fn (): ColorPink => new ColorPink(); + $color = static fn(): ColorPink => new ColorPink(); $factory = new Factory( new SimpleContainer(), @@ -984,7 +984,7 @@ public function testClosureInProperty(): void 'class' => PropertyTest::class, '$property' => $color, ], - ] + ], ); /** @var PropertyTest $object */ @@ -1003,7 +1003,7 @@ public function testReferenceInProperty(): void 'class' => PropertyTest::class, '$property' => Reference::to('color'), ], - ] + ], ); /** @var PropertyTest $object */ @@ -1021,9 +1021,9 @@ public function testDynamicReferenceInProperty(): void [ PropertyTest::class => [ 'class' => PropertyTest::class, - '$property' => DynamicReference::to(static fn () => $color), + '$property' => DynamicReference::to(static fn() => $color), ], - ] + ], ); /** @var PropertyTest $object */ @@ -1034,7 +1034,7 @@ public function testDynamicReferenceInProperty(): void public function testClosureInMethod(): void { - $color = static fn (): ColorPink => new ColorPink(); + $color = static fn(): ColorPink => new ColorPink(); $factory = new Factory( new SimpleContainer(), @@ -1043,7 +1043,7 @@ public function testClosureInMethod(): void 'class' => MethodTest::class, 'setValue()' => [$color], ], - ] + ], ); /** @var MethodTest $object */ @@ -1062,7 +1062,7 @@ public function testReferenceInMethod(): void 'class' => MethodTest::class, 'setValue()' => [Reference::to('color')], ], - ] + ], ); /** @var MethodTest $object */ @@ -1080,9 +1080,9 @@ public function testDynamicReferenceInMethod(): void [ MethodTest::class => [ 'class' => MethodTest::class, - 'setValue()' => [DynamicReference::to(static fn () => $color)], + 'setValue()' => [DynamicReference::to(static fn() => $color)], ], - ] + ], ); /** @var MethodTest $object */ @@ -1099,7 +1099,7 @@ public function testAlias(): void EngineInterface::class => Reference::to('engine'), 'engine' => Reference::to('engine-mark-one'), 'engine-mark-one' => EngineMarkOne::class, - ] + ], ); $engine1 = $factory->create('engine-mark-one'); @@ -1116,7 +1116,7 @@ public function testUndefinedDependencies(): void { $factory = new Factory( new SimpleContainer(), - ['car' => Car::class] + ['car' => Car::class], ); $this->expectException(NotInstantiableClassException::class); @@ -1130,7 +1130,7 @@ public function testDependencies(): void [ 'car' => Car::class, EngineInterface::class => EngineMarkTwo::class, - ] + ], ); /** @var Car $car */ @@ -1145,8 +1145,8 @@ public function testCallableDefinition(): void new SimpleContainer(), [ EngineInterface::class => EngineMarkOne::class, - 'test' => static fn (EngineInterface $engine) => $engine, - ] + 'test' => static fn(EngineInterface $engine) => $engine, + ], ); $object = $factory->create('test'); @@ -1161,7 +1161,7 @@ public function testArrayStaticCallableDefinition(): void [ EngineInterface::class => EngineMarkOne::class, 'car' => [CarFactory::class, 'create'], - ] + ], ); $car = $factory->create('car'); @@ -1178,7 +1178,7 @@ public function testArrayDynamicCallableDefinition(): void ColorInterface::class => ColorPink::class, CarFactory::class => CarFactory::class, 'car' => [CarFactory::class, 'createWithColor'], - ] + ], ); $car = $factory->create('car'); @@ -1194,7 +1194,7 @@ public function testArrayDynamicCallableDefinitionWithObject(): void [ ColorInterface::class => ColorPink::class, 'car' => [new CarFactory(), 'createWithColor'], - ] + ], ); $car = $factory->create('car'); @@ -1210,7 +1210,7 @@ public function testInvokableDefinition(): void [ EngineInterface::class => EngineMarkOne::class, 'invokable' => new InvokableCarFactory(), - ] + ], ); $object = $factory->create('invokable'); @@ -1242,7 +1242,7 @@ public function testReferencesInArrayInDependencies(): void ], ], ], - ] + ], ); $car = $factory->create('car'); @@ -1271,7 +1271,7 @@ public function testCallableArrayValueInConstructor(): void $array, ], ], - ] + ], ); /** @var Car $object */ @@ -1349,8 +1349,8 @@ public function testDefinitionInterfaceAsDefinitionInConstructorArguments(): voi $this->expectException(InvalidConfigException::class); $this->expectExceptionMessageMatches( - '~^Only references are allowed in constructor arguments, a definition object was provided: ' . - '(\\\\|)Yiisoft\\\\Definitions\\\\ValueDefinition::~' + '~^Only references are allowed in constructor arguments, a definition object was provided: ' + . '(\\\\|)Yiisoft\\\\Definitions\\\\ValueDefinition::~', ); new Factory(new SimpleContainer(), ['test' => $definition]); } @@ -1382,9 +1382,9 @@ public function testScalarConstructorArgument(): void $this->expectException(NotInstantiableException::class); $this->expectExceptionMessage( - 'Can not determine value of the "name" parameter of type "string" when instantiating ' . - '"Yiisoft\Factory\Tests\Support\ScalarConstructorArgument::__construct()". ' . - 'Please specify argument explicitly.' + 'Can not determine value of the "name" parameter of type "string" when instantiating ' + . '"Yiisoft\Factory\Tests\Support\ScalarConstructorArgument::__construct()". ' + . 'Please specify argument explicitly.', ); $factory->create(ScalarConstructorArgument::class); } @@ -1410,9 +1410,9 @@ public function testContainerInterfaceInDynamicReferenceWorkWithContainerViaAlia $container, [ EngineInterface::class => EngineMarkTwo::class, - 'e' => fn (ContainerInterface $c) => $c->get(EngineInterface::class), + 'e' => fn(ContainerInterface $c) => $c->get(EngineInterface::class), 'engine' => Reference::to('e'), - ] + ], ); $this->assertInstanceOf(EngineMarkOne::class, $factory->create('engine')); @@ -1428,8 +1428,8 @@ public function testContainerInterfaceInDynamicReferenceWorkWithContainerViaAlia $container, [ EngineInterface::class => EngineMarkTwo::class, - 'engine' => DynamicReference::to(fn (ContainerInterface $c) => $c->get(EngineInterface::class)), - ] + 'engine' => DynamicReference::to(fn(ContainerInterface $c) => $c->get(EngineInterface::class)), + ], ); $this->assertInstanceOf(EngineMarkOne::class, $factory->create('engine')); @@ -1444,8 +1444,8 @@ public function testAliasedDynamicReference(): void $factory = new Factory( $container, [ - 'engine' => DynamicReference::to(fn (EngineInterface $e) => $e), - ] + 'engine' => DynamicReference::to(fn(EngineInterface $e) => $e), + ], ); $this->assertInstanceOf(EngineMarkOne::class, $factory->create('engine')); @@ -1461,8 +1461,8 @@ public function testAliasedFactoryHasPriorityInDynamicReference(): void $container, [ EngineInterface::class => new EngineMarkTwo(), - 'engine' => DynamicReference::to(fn (EngineInterface $e) => $e), - ] + 'engine' => DynamicReference::to(fn(EngineInterface $e) => $e), + ], ); $this->assertInstanceOf(EngineMarkTwo::class, $factory->create('engine')); @@ -1478,7 +1478,7 @@ public function testAliasedReference(): void $container, [ 'engine' => Reference::to(EngineInterface::class), - ] + ], ); $this->assertInstanceOf(EngineMarkOne::class, $factory->create('engine')); @@ -1496,7 +1496,7 @@ public function testReferenceInConstructorInFactoryWithContainer(): void Car::class => [ '__construct()' => [Reference::to(EngineInterface::class)], ], - ] + ], ); $object1 = $factory->create(Car::class); @@ -1516,9 +1516,9 @@ public function testDynamicReferenceInConstructorInFactoryWithContainer(): void $container, [ Car::class => [ - '__construct()' => [DynamicReference::to(fn (EngineInterface $e) => $e)], + '__construct()' => [DynamicReference::to(fn(EngineInterface $e) => $e)], ], - ] + ], ); $this->assertInstanceOf(EngineMarkOne::class, $factory->create(Car::class)->getEngine()); @@ -1537,7 +1537,7 @@ public function testFactoryHasPriorityInReference(): void Car::class => [ '__construct()' => [Reference::to(EngineInterface::class)], ], - ] + ], ); $this->assertInstanceOf(EngineMarkTwo::class, $factory->create(Car::class)->getEngine()); @@ -1553,9 +1553,9 @@ public function testAliasedDynamicReferenceInConstructor(): void $container, [ Car::class => [ - '__construct()' => [DynamicReference::to(fn (EngineInterface $e) => $e)], + '__construct()' => [DynamicReference::to(fn(EngineInterface $e) => $e)], ], - ] + ], ); $this->assertInstanceOf(EngineMarkOne::class, $factory->create(Car::class)->getEngine()); @@ -1573,11 +1573,11 @@ public function testContainerInterfaceDynamicReferenceInConstructor(): void Car::class => [ '__construct()' => [ DynamicReference::to( - static fn (ContainerInterface $c) => $c->get(EngineInterface::class) + static fn(ContainerInterface $c) => $c->get(EngineInterface::class), ), ], ], - ] + ], ); $this->assertInstanceOf(EngineMarkOne::class, $factory->create(Car::class)->getEngine()); @@ -1596,11 +1596,11 @@ public function testContainerInterfaceInDynamicReferenceWorkWithContainer(): voi Car::class => [ '__construct()' => [ DynamicReference::to( - static fn (ContainerInterface $c) => $c->get(EngineInterface::class) + static fn(ContainerInterface $c) => $c->get(EngineInterface::class), ), ], ], - ] + ], ); $this->assertInstanceOf(EngineMarkOne::class, $factory->create(Car::class)->getEngine()); @@ -1617,9 +1617,9 @@ public function testFactoryHasPriorityInDynamicReference(): void [ EngineInterface::class => EngineMarkTwo::class, Car::class => [ - '__construct()' => [DynamicReference::to(fn (EngineInterface $e) => $e)], + '__construct()' => [DynamicReference::to(fn(EngineInterface $e) => $e)], ], - ] + ], ); $this->assertInstanceOf(EngineMarkTwo::class, $factory->create(Car::class)->getEngine()); @@ -1635,9 +1635,9 @@ public function testFactoryHasPriorityInClosureViaReference(): void $container, [ EngineInterface::class => EngineMarkTwo::class, - 'e' => fn (EngineInterface $e) => $e, + 'e' => fn(EngineInterface $e) => $e, 'engine' => Reference::to('e'), - ] + ], ); $this->assertInstanceOf(EngineMarkTwo::class, $factory->create('engine')); @@ -1702,9 +1702,9 @@ public function testUnionBuiltInTypesDependency(): void $this->expectException(NotInstantiableException::class); $this->expectExceptionMessage( - 'Can not determine value of the "values" parameter of type "string|int" when instantiating ' . - '"Yiisoft\Factory\Tests\Support\UnionBuiltInTypes::__construct()". ' . - 'Please specify argument explicitly.' + 'Can not determine value of the "values" parameter of type "string|int" when instantiating ' + . '"Yiisoft\Factory\Tests\Support\UnionBuiltInTypes::__construct()". ' + . 'Please specify argument explicitly.', ); $factory->create(UnionBuiltInTypes::class); } diff --git a/tests/Support/Car.php b/tests/Support/Car.php index a212d602..faab0efb 100644 --- a/tests/Support/Car.php +++ b/tests/Support/Car.php @@ -8,9 +8,7 @@ final class Car { public ?ColorInterface $color = null; - public function __construct(private EngineInterface $engine, private array $moreEngines = []) - { - } + public function __construct(private EngineInterface $engine, private array $moreEngines = []) {} public function getEngine(): EngineInterface { diff --git a/tests/Support/Circular/Chicken.php b/tests/Support/Circular/Chicken.php index 44d31380..766ebbdb 100644 --- a/tests/Support/Circular/Chicken.php +++ b/tests/Support/Circular/Chicken.php @@ -6,7 +6,5 @@ final class Chicken { - public function __construct(Egg $egg) - { - } + public function __construct(Egg $egg) {} } diff --git a/tests/Support/Circular/CircularA.php b/tests/Support/Circular/CircularA.php index 06dbdcfd..9adb8c0d 100644 --- a/tests/Support/Circular/CircularA.php +++ b/tests/Support/Circular/CircularA.php @@ -6,7 +6,5 @@ final class CircularA { - public function __construct(public ?CircularB $b = null) - { - } + public function __construct(public ?CircularB $b = null) {} } diff --git a/tests/Support/Circular/CircularB.php b/tests/Support/Circular/CircularB.php index 5b2486a7..4ef9af30 100644 --- a/tests/Support/Circular/CircularB.php +++ b/tests/Support/Circular/CircularB.php @@ -6,7 +6,5 @@ final class CircularB { - public function __construct(public ?CircularA $a = null) - { - } + public function __construct(public ?CircularA $a = null) {} } diff --git a/tests/Support/Circular/Egg.php b/tests/Support/Circular/Egg.php index d2692086..79f2002f 100644 --- a/tests/Support/Circular/Egg.php +++ b/tests/Support/Circular/Egg.php @@ -6,7 +6,5 @@ final class Egg { - public function __construct(Chicken $chicken) - { - } + public function __construct(Chicken $chicken) {} } diff --git a/tests/Support/Circular/TreeItem.php b/tests/Support/Circular/TreeItem.php index f7ab55a3..e2c39dad 100644 --- a/tests/Support/Circular/TreeItem.php +++ b/tests/Support/Circular/TreeItem.php @@ -6,7 +6,5 @@ final class TreeItem { - public function __construct(self $treeItem) - { - } + public function __construct(self $treeItem) {} } diff --git a/tests/Support/Cube.php b/tests/Support/Cube.php index 3b3a3f3e..ff75c857 100644 --- a/tests/Support/Cube.php +++ b/tests/Support/Cube.php @@ -6,9 +6,7 @@ final class Cube { - public function __construct(private ColorInterface $color) - { - } + public function __construct(private ColorInterface $color) {} public function getColor(): ColorInterface { diff --git a/tests/Support/EngineMarkOne.php b/tests/Support/EngineMarkOne.php index f77bff5c..ac6a2173 100644 --- a/tests/Support/EngineMarkOne.php +++ b/tests/Support/EngineMarkOne.php @@ -8,9 +8,7 @@ final class EngineMarkOne implements EngineInterface { public const NAME = 'Mark One'; - public function __construct(private int $number = 0) - { - } + public function __construct(private int $number = 0) {} public function getName(): string { diff --git a/tests/Support/Firefighter.php b/tests/Support/Firefighter.php index e579f5cf..7a25448d 100644 --- a/tests/Support/Firefighter.php +++ b/tests/Support/Firefighter.php @@ -6,9 +6,7 @@ final class Firefighter { - public function __construct(private ?string $name) - { - } + public function __construct(private ?string $name) {} public function getName(): ?string { diff --git a/tests/Support/GearBox.php b/tests/Support/GearBox.php index 2df8f193..63f557fb 100644 --- a/tests/Support/GearBox.php +++ b/tests/Support/GearBox.php @@ -9,7 +9,5 @@ */ final class GearBox { - public function __construct(private int $maxGear = 5) - { - } + public function __construct(private int $maxGear = 5) {} } diff --git a/tests/Support/NullableConcreteDependency.php b/tests/Support/NullableConcreteDependency.php index 00fd9705..9944cd55 100644 --- a/tests/Support/NullableConcreteDependency.php +++ b/tests/Support/NullableConcreteDependency.php @@ -6,9 +6,7 @@ final class NullableConcreteDependency { - public function __construct(private ?Car $car) - { - } + public function __construct(private ?Car $car) {} public function getCar(): Car { diff --git a/tests/Support/NullableInterfaceDependency.php b/tests/Support/NullableInterfaceDependency.php index 98225e8f..17cec31b 100644 --- a/tests/Support/NullableInterfaceDependency.php +++ b/tests/Support/NullableInterfaceDependency.php @@ -6,9 +6,7 @@ final class NullableInterfaceDependency { - public function __construct(private ?EngineInterface $engine) - { - } + public function __construct(private ?EngineInterface $engine) {} public function getEngine(): ?EngineInterface { diff --git a/tests/Support/NullableOptionalConcreteDependency.php b/tests/Support/NullableOptionalConcreteDependency.php index dc0c3e82..586ef314 100644 --- a/tests/Support/NullableOptionalConcreteDependency.php +++ b/tests/Support/NullableOptionalConcreteDependency.php @@ -6,7 +6,5 @@ final class NullableOptionalConcreteDependency { - public function __construct(?Car $car = null) - { - } + public function __construct(?Car $car = null) {} } diff --git a/tests/Support/NullableOptionalInterfaceDependency.php b/tests/Support/NullableOptionalInterfaceDependency.php index b8644f8c..42789786 100644 --- a/tests/Support/NullableOptionalInterfaceDependency.php +++ b/tests/Support/NullableOptionalInterfaceDependency.php @@ -6,7 +6,5 @@ final class NullableOptionalInterfaceDependency { - public function __construct(?EngineInterface $engine = null) - { - } + public function __construct(?EngineInterface $engine = null) {} } diff --git a/tests/Support/NullableScalarConstructorArgument.php b/tests/Support/NullableScalarConstructorArgument.php index efe31397..161812c4 100644 --- a/tests/Support/NullableScalarConstructorArgument.php +++ b/tests/Support/NullableScalarConstructorArgument.php @@ -6,9 +6,7 @@ final class NullableScalarConstructorArgument { - public function __construct(private ?string $name) - { - } + public function __construct(private ?string $name) {} public function getName(): ?string { diff --git a/tests/Support/Phone.php b/tests/Support/Phone.php index 1f531294..4d2a300c 100644 --- a/tests/Support/Phone.php +++ b/tests/Support/Phone.php @@ -6,15 +6,14 @@ final class Phone { + public bool $dev = false; + public ?string $codeName = null; private ?string $id = null; private array $colors; private array $apps = []; private ?string $author = null; private ?string $country = null; - public bool $dev = false; - public ?string $codeName = null; - public function __construct(private ?string $name = null, private ?string $version = null, string ...$colors) { $this->colors = $colors; diff --git a/tests/Support/PinkCircle.php b/tests/Support/PinkCircle.php index 4301a6fd..10b52dc3 100644 --- a/tests/Support/PinkCircle.php +++ b/tests/Support/PinkCircle.php @@ -6,9 +6,7 @@ final class PinkCircle { - public function __construct(private ColorPink $color) - { - } + public function __construct(private ColorPink $color) {} public function getColor(): ColorPink { diff --git a/tests/Support/ScalarConstructorArgument.php b/tests/Support/ScalarConstructorArgument.php index 02a17532..70fbd6bf 100644 --- a/tests/Support/ScalarConstructorArgument.php +++ b/tests/Support/ScalarConstructorArgument.php @@ -6,9 +6,7 @@ final class ScalarConstructorArgument { - public function __construct(private string $name) - { - } + public function __construct(private string $name) {} public function getName(): string { diff --git a/tests/Support/TwoParametersDependency.php b/tests/Support/TwoParametersDependency.php index c0661456..bb248dee 100644 --- a/tests/Support/TwoParametersDependency.php +++ b/tests/Support/TwoParametersDependency.php @@ -6,9 +6,7 @@ final class TwoParametersDependency { - public function __construct(private string $firstParameter, private string $secondParameter) - { - } + public function __construct(private string $firstParameter, private string $secondParameter) {} public function getFirstParameter(): string { diff --git a/tests/Support/UnionBuiltInTypes.php b/tests/Support/UnionBuiltInTypes.php index 1321ed46..d0505afd 100644 --- a/tests/Support/UnionBuiltInTypes.php +++ b/tests/Support/UnionBuiltInTypes.php @@ -6,7 +6,5 @@ final class UnionBuiltInTypes { - public function __construct(string|int $values) - { - } + public function __construct(string|int $values) {} } From 7ad7992e87393f214a1593ef3c1471e5190ca6b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Wed, 14 Jan 2026 15:48:24 +0400 Subject: [PATCH 3/4] fix config --- .php-cs-fixer.dist.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2d5d3766..b1061357 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -9,8 +9,6 @@ $finder = (new Finder())->in([ __DIR__ . '/src', __DIR__ . '/tests', -])->notPath([ - 'MockHelper.php' ]); // TODO: Update the configuration after raising the minimum PHP version From 31108dcb25b0a54d0651be08452aeda4370392a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Wed, 14 Jan 2026 15:49:13 +0400 Subject: [PATCH 4/4] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51685e24..ffd7450d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 1.3.2 under development -- no changes in this release. +- Enh #220: Explicitly import functions in "use" section (@mspirkov) ## 1.3.1 December 02, 2025