From de827f3a291be648d41225b6d2f9b19ab048bc27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 3 Sep 2023 14:13:06 +0200 Subject: [PATCH] Fix: Switch order of parameters --- roave-bc-check.yaml | 1 + src/Faker/Container/ContainerBuilder.php | 4 ++-- test/Faker/Extension/ContainerBuilderTest.php | 14 +++++++------- test/Faker/GeneratorTest.php | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/roave-bc-check.yaml b/roave-bc-check.yaml index 8d116c8eeb..ec55cb0747 100644 --- a/roave-bc-check.yaml +++ b/roave-bc-check.yaml @@ -18,3 +18,4 @@ parameters: - '#\[BC\] CHANGED: The parameter \$container of Faker\\Generator\#\_\_construct\(\) changed from Psr\\Container\\ContainerInterface\|null to Faker\\Container\\ContainerInterface\|null#' - '#\[BC\] CHANGED: The number of required arguments for Faker\\Container\\ContainerBuilder\#add\(\) increased from 1 to 2#' - '#\[BC\] CHANGED: The parameter \$name of Faker\\Container\\ContainerBuilder\#add\(\) changed from string\|null to a non-contravariant string#' + - '#\[BC\] CHANGED: The parameter \$value of Faker\\Container\\ContainerBuilder\#add\(\) changed from no type to a non-contravariant string#' diff --git a/src/Faker/Container/ContainerBuilder.php b/src/Faker/Container/ContainerBuilder.php index 012554713c..6a9c4747f0 100644 --- a/src/Faker/Container/ContainerBuilder.php +++ b/src/Faker/Container/ContainerBuilder.php @@ -29,7 +29,7 @@ final class ContainerBuilder * * @throws \InvalidArgumentException */ - public function add($value, string $name): self + public function add(string $name, $value): self { if (!is_string($value) && !is_callable($value) && !is_object($value)) { throw new \InvalidArgumentException(sprintf( @@ -71,7 +71,7 @@ public static function getDefault(): ContainerInterface $instance = new self(); foreach (self::defaultExtensions() as $id => $definition) { - $instance->add($definition, $id); + $instance->add($id, $definition); } return $instance->build(); diff --git a/test/Faker/Extension/ContainerBuilderTest.php b/test/Faker/Extension/ContainerBuilderTest.php index 02b64a2263..a86d81cde7 100644 --- a/test/Faker/Extension/ContainerBuilderTest.php +++ b/test/Faker/Extension/ContainerBuilderTest.php @@ -29,7 +29,7 @@ public function testAddRejectsInvalidValue($value): void ContainerBuilder::class, )); - $containerBuilder->add($value, 'foo'); + $containerBuilder->add('foo', $value); } /** @@ -71,7 +71,7 @@ public function testBuild(): void { $builder = new ContainerBuilder(); - $builder->add(File::class, 'foo'); + $builder->add('foo', File::class); $container = $builder->build(); @@ -82,8 +82,8 @@ public function testBuildWithDuplicates(): void { $builder = new ContainerBuilder(); - $builder->add(File::class, 'foo'); - $builder->add(File::class, 'foo'); + $builder->add('foo', File::class); + $builder->add('foo', File::class); $container = $builder->build(); @@ -94,7 +94,7 @@ public function testBuildWithObject(): void { $builder = new ContainerBuilder(); - $builder->add(new File(), 'foo'); + $builder->add('foo', new File()); $container = $builder->build(); @@ -105,9 +105,9 @@ public function testBuildWithCallable(): void { $builder = new ContainerBuilder(); - $builder->add(static function () { + $builder->add('foo', static function () { return new File(); - }, 'foo'); + }); $container = $builder->build(); diff --git a/test/Faker/GeneratorTest.php b/test/Faker/GeneratorTest.php index d8e7b11f7d..3adcf06534 100644 --- a/test/Faker/GeneratorTest.php +++ b/test/Faker/GeneratorTest.php @@ -135,7 +135,7 @@ public function testFormatTransfersArgumentsToFormatter(): void public function testFormatterCallsGenerator(): void { $builder = new ContainerBuilder(); - $builder->add(Blood::class, BloodExtension::class); + $builder->add(BloodExtension::class, Blood::class); $faker = new Generator($builder->build()); $output = $faker->format('bloodType');