Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Switch order of parameters #703

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading