Skip to content

Commit

Permalink
Fix: Switch order of parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Sep 3, 2023
1 parent fb0d147 commit de827f3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions roave-bc-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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#'
4 changes: 2 additions & 2 deletions src/Faker/Container/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions test/Faker/Extension/ContainerBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testAddRejectsInvalidValue($value): void
ContainerBuilder::class,
));

$containerBuilder->add($value, 'foo');
$containerBuilder->add('foo', $value);
}

/**
Expand Down Expand Up @@ -71,7 +71,7 @@ public function testBuild(): void
{
$builder = new ContainerBuilder();

$builder->add(File::class, 'foo');
$builder->add('foo', File::class);

$container = $builder->build();

Expand All @@ -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();

Expand All @@ -94,7 +94,7 @@ public function testBuildWithObject(): void
{
$builder = new ContainerBuilder();

$builder->add(new File(), 'foo');
$builder->add('foo', new File());

$container = $builder->build();

Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion test/Faker/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit de827f3

Please sign in to comment.