Skip to content

Commit ff2aaa6

Browse files
nikophilkbond
authored andcommitted
bot: fix cs [skip ci]
1 parent 7296dd9 commit ff2aaa6

30 files changed

+334
-246
lines changed

config/behat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Zenstruck\Foundry\Test\Behat\FoundryContext;
1818
use Zenstruck\Foundry\Test\Behat\ObjectRegistry;
1919

20-
return static function (ContainerConfigurator $container): void {
20+
return static function(ContainerConfigurator $container): void {
2121
$container->services()
2222
->set('.zenstruck_foundry.behat.factory_resolver', FactoryShortNameResolver::class)
2323
->args([

src/Story/FixtureStoryResolver.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@ public function resolve(string $fixtureOrGroupName): array
4343
return $this->resolveGroup($fixtureOrGroupName);
4444
}
4545

46-
throw FixtureStoryNotFound::forNameOrGroup(
47-
$fixtureOrGroupName,
48-
[...$this->availableFixtureNames(), ...$this->availableGroupNames()]
49-
);
46+
throw FixtureStoryNotFound::forNameOrGroup($fixtureOrGroupName, [...$this->availableFixtureNames(), ...$this->availableGroupNames()]);
5047
}
5148

5249
public function hasAnyFixtures(): bool
5350
{
54-
return count($this->fixtureStories) > 0;
51+
return \count($this->fixtureStories) > 0;
5552
}
5653

5754
public function hasFixture(string $name): bool
@@ -61,7 +58,7 @@ public function hasFixture(string $name): bool
6158

6259
public function hasOnlyOneFixture(): bool
6360
{
64-
return count($this->fixtureStories) === 1;
61+
return 1 === \count($this->fixtureStories);
6562
}
6663

6764
/**

src/Test/Behat/Exception/DamaNativeExtensionIncompatibility.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the zenstruck/foundry package.
5+
*
6+
* (c) Kevin Bond <kevinbond@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Zenstruck\Foundry\Test\Behat\Exception;
413

514
final class DamaNativeExtensionIncompatibility extends \LogicException

src/Test/Behat/Exception/FactoryNotResolvable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class FactoryNotResolvable extends \RuntimeException
2121
{
2222
public static function forName(string $name): self
2323
{
24-
return new self("Cannot resolve factory for name \"$name\": short name does not exist");
24+
return new self("Cannot resolve factory for name \"{$name}\": short name does not exist");
2525
}
2626

2727
/**

src/Test/Behat/Exception/InvalidObjectParameter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ final class InvalidObjectParameter extends \RuntimeException
2121
{
2222
public static function objectReferencedInTableDoesNotExist(string $column, ObjectNotFound $previous): self
2323
{
24-
return new self("A reference to an object cannot be resolved in the table, at column \"$column\": {$previous->getMessage()}", previous: $previous);
24+
return new self("A reference to an object cannot be resolved in the table, at column \"{$column}\": {$previous->getMessage()}", previous: $previous);
2525
}
2626

2727
public static function invalidDate(string $column, string $invalidDate, \Throwable $previous): self
2828
{
29-
return new self("Invalid date given \"$invalidDate\", at column \"$column\"", previous: $previous);
29+
return new self("Invalid date given \"{$invalidDate}\", at column \"{$column}\"", previous: $previous);
3030
}
3131

3232
public static function invalidEnumValue(string $column, string $invalidEnumValue): self
3333
{
34-
return new self("Invalid enum value given \"$invalidEnumValue\", at column \"$column\"");
34+
return new self("Invalid enum value given \"{$invalidEnumValue}\", at column \"{$column}\"");
3535
}
3636
}

src/Test/Behat/Exception/InvalidResetDbTag.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the zenstruck/foundry package.
5+
*
6+
* (c) Kevin Bond <kevinbond@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Zenstruck\Foundry\Test\Behat\Exception;
413

514
use Behat\Behat\EventDispatcher\Event\BeforeFeatureTested;
@@ -24,19 +33,19 @@ public function __construct(string $message, BeforeFeatureTested|BeforeScenarioT
2433
continue;
2534
}
2635

27-
if (str_contains($file, $path)) {
28-
$file = substr($file, strpos($file, $path)); // @phpstan-ignore argument.type (strpos cannot be false if $path is contained in $file)
36+
if (\str_contains($file, $path)) {
37+
$file = \mb_substr($file, \mb_strpos($file, $path)); // @phpstan-ignore argument.type (strpos cannot be false if $path is contained in $file)
2938
break;
3039
}
3140
}
3241
}
3342

34-
$errorFileAndLine = match($event::class){
43+
$errorFileAndLine = match ($event::class) {
3544
BeforeFeatureTested::class => "{$file}:{$event->getFeature()->getLine()}",
3645
BeforeScenarioTested::class => "{$file}:{$event->getScenario()->getLine()}",
3746
};
3847

39-
parent::__construct("$message\nAt $errorFileAndLine");
48+
parent::__construct("{$message}\nAt {$errorFileAndLine}");
4049
}
4150

4251
public static function bothTagsUsed(BeforeScenarioTested $event): self

src/Test/Behat/Exception/ObjectNotFound.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ final class ObjectNotFound extends \RuntimeException
2121
{
2222
public static function forFactoryAndName(string $factoryShortName, string $name): self
2323
{
24-
return new self("Object \"$factoryShortName $name\" was not found.");
24+
return new self("Object \"{$factoryShortName} {$name}\" was not found.");
2525
}
2626

2727
/**
2828
* @param class-string $objectName
2929
*/
3030
public static function forClassAndName(string $objectName, string $name): self
3131
{
32-
return new self("Object of class \"$objectName\" with name \"$name\" was not found.");
32+
return new self("Object of class \"{$objectName}\" with name \"{$name}\" was not found.");
3333
}
3434
}

src/Test/Behat/FactoryShortNameResolver.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Zenstruck\Foundry\Factory;
1919
use Zenstruck\Foundry\ObjectFactory;
2020
use Zenstruck\Foundry\Test\Behat\Exception\FactoryNotResolvable;
21+
2122
use function Symfony\Component\String\u;
2223

2324
/**
@@ -51,7 +52,7 @@ public function __construct(iterable $factories)
5152
$this->factoryMap[$shortName] ??= [];
5253
$this->factoryMap[$shortName][] = $factory;
5354

54-
$plural = \strtolower($this->factoryShortNameAttribute($factory::class)->pluralName ?? $inflector->pluralize($shortName)[0]);
55+
$plural = \mb_strtolower($this->factoryShortNameAttribute($factory::class)->pluralName ?? $inflector->pluralize($shortName)[0]);
5556
$this->factoryMap[$plural] ??= [];
5657
$this->factoryMap[$plural][] = $factory;
5758
}
@@ -64,7 +65,7 @@ public function __construct(iterable $factories)
6465
*/
6566
public function factoryFor(string $shortName): ObjectFactory
6667
{
67-
$normalized = \strtolower($shortName);
68+
$normalized = \mb_strtolower($shortName);
6869

6970
if (!isset($this->factoryMap[$normalized])) {
7071
throw FactoryNotResolvable::forName($shortName);
@@ -73,7 +74,7 @@ public function factoryFor(string $shortName): ObjectFactory
7374
$factories = $this->factoryMap[$normalized];
7475

7576
if (\count($factories) > 1) {
76-
throw FactoryNotResolvable::conflict($shortName, array_map(static fn(ObjectFactory $f) => $f::class, $factories));
77+
throw FactoryNotResolvable::conflict($shortName, \array_map(static fn(ObjectFactory $f) => $f::class, $factories));
7778
}
7879

7980
return $factories[0]::new();
@@ -123,7 +124,7 @@ private function shortNameFor(string $factoryClass): string
123124
$attribute = $this->factoryShortNameAttribute($factoryClass);
124125

125126
if ($attribute) {
126-
return \strtolower($attribute->shortName);
127+
return \mb_strtolower($attribute->shortName);
127128
}
128129

129130
$shortClass = u((new \ReflectionClass($factoryClass))->getShortName());

src/Test/Behat/FoundryCallFilter.php

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the zenstruck/foundry package.
5+
*
6+
* (c) Kevin Bond <kevinbond@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Zenstruck\Foundry\Test\Behat;
413

514
use Behat\Behat\Definition\Call\DefinitionCall;
@@ -14,7 +23,7 @@
1423
/**
1524
* @internal
1625
*
17-
* Transforms TableNodes into FoundryTableNodes where all types are resolved.
26+
* Transforms TableNodes into FoundryTableNodes where all types are resolved
1827
*/
1928
final class FoundryCallFilter implements CallFilter
2029
{
@@ -41,28 +50,26 @@ public function filterCall(Call $call): Call
4150
if (
4251
!$call instanceof DefinitionCall
4352
|| !$call->getCallee()->getReflection() instanceof \ReflectionMethod
44-
|| $call->getCallee()->getReflection()->class !== FoundryContext::class
53+
|| FoundryContext::class !== $call->getCallee()->getReflection()->class
4554
) {
4655
return $call;
4756
}
4857

4958
$arguments = $call->getArguments();
5059

5160
if (!isset($arguments['factoryShortName'])) {
52-
throw new \InvalidArgumentException(
53-
<<<ERROR
61+
throw new \InvalidArgumentException(<<<ERROR
5462
Cannot filter call without a "\$factoryShortName" argument.
5563
This must be the name of the argument in the #[Given], #[When], #[Then] definitions."
56-
ERROR
57-
);
64+
ERROR);
5865
}
59-
66+
6067
return new DefinitionCall(
6168
$call->getEnvironment(),
6269
$call->getFeature(),
6370
$call->getStep(),
6471
$call->getCallee(),
65-
array_map(
72+
\array_map(
6673
fn(mixed $argument) => match ($argument instanceof TableNode) {
6774
true => $this->normalizeObjectParameters($argument, $arguments['factoryShortName']),
6875
false => $argument,
@@ -77,30 +84,30 @@ private function normalizeObjectParameters(TableNode $tableNode, string $factory
7784
{
7885
$table = $tableNode->getTable();
7986

80-
$headKey = array_key_first($table);
81-
$thead = array_shift($table);
87+
$headKey = \array_key_first($table);
88+
$thead = \array_shift($table);
8289

8390
return FoundryTableNode::create(
8491
$this->factoryResolver,
8592
$this->objectRegistry,
86-
(\Closure::bind(
87-
fn () => $this->maxLineLength,
93+
\Closure::bind(
94+
fn() => $this->maxLineLength,
8895
$tableNode,
8996
TableNode::class
90-
)()),
97+
)(),
9198
[ // @phpstan-ignore argument.type (TableNode has the same problem: array $table is not really lists)
9299
$headKey => $thead, // @phpstan-ignore array.invalidKey
93-
...array_map(
94-
function (array $parameters) use ($thead, $factoryShortName): array {
100+
...\array_map(
101+
function(array $parameters) use ($thead, $factoryShortName): array {
95102
$normalized = [];
96103
foreach ($parameters as $key => $value) {
97104
if (!isset($thead[$key])) {
98-
throw new \LogicException("Table has no column for parameter \"$key\". This should never happen, table integrity is checked in TableNode.");
105+
throw new \LogicException("Table has no column for parameter \"{$key}\". This should never happen, table integrity is checked in TableNode.");
99106
}
100107

101108
$propertyName = $thead[$key];
102109

103-
if ($propertyName === '_ref') {
110+
if ('_ref' === $propertyName) {
104111
$normalized['_ref'] = $value;
105112

106113
continue;
@@ -124,7 +131,7 @@ function (array $parameters) use ($thead, $factoryShortName): array {
124131
continue;
125132
}
126133

127-
if (preg_match('/^<ref\((?<factoryShortName>[^,]+), (?<objectName>[^)]+)\)>$/', $value, $matches)) {
134+
if (\preg_match('/^<ref\((?<factoryShortName>[^,]+), (?<objectName>[^)]+)\)>$/', $value, $matches)) {
128135
try {
129136
$normalized[$propertyName] = $this->objectRegistry->getByFactoryShortName($matches['factoryShortName'], $matches['objectName']);
130137
} catch (ObjectNotFound $e) {
@@ -153,7 +160,7 @@ function (array $parameters) use ($thead, $factoryShortName): array {
153160
continue;
154161
}
155162

156-
if (is_a($expectedTypeClass, \DateTimeInterface::class, allow_string: true)) {
163+
if (\is_a($expectedTypeClass, \DateTimeInterface::class, allow_string: true)) {
157164
try {
158165
$normalized[$propertyName] = new $expectedTypeClass($value);
159166

@@ -163,15 +170,15 @@ function (array $parameters) use ($thead, $factoryShortName): array {
163170
}
164171
}
165172

166-
if (is_a($expectedTypeClass, \BackedEnum::class, allow_string: true)) {
167-
$value = is_numeric($value) ? (int)$value : $value;
173+
if (\is_a($expectedTypeClass, \BackedEnum::class, allow_string: true)) {
174+
$value = \is_numeric($value) ? (int) $value : $value;
168175

169-
$normalized[$propertyName] = $expectedTypeClass::tryFrom($value) ?? throw InvalidObjectParameter::invalidEnumValue($propertyName, (string)$value);
176+
$normalized[$propertyName] = $expectedTypeClass::tryFrom($value) ?? throw InvalidObjectParameter::invalidEnumValue($propertyName, (string) $value);
170177

171178
continue;
172179
}
173180

174-
throw new \LogicException("Cannot normalize parameter \"$propertyName\" with value \"$value\".");
181+
throw new \LogicException("Cannot normalize parameter \"{$propertyName}\" with value \"{$value}\".");
175182
}
176183

177184
return $normalized;
@@ -201,7 +208,7 @@ private function getPropertyTypeIfClass(\ReflectionClass $class, string $propert
201208
!isset($property)
202209
|| !($type = $property->getType()) instanceof \ReflectionNamedType
203210
|| $type->isBuiltin()
204-
|| !class_exists($type->getName())
211+
|| !\class_exists($type->getName())
205212
) {
206213
return null;
207214
}

0 commit comments

Comments
 (0)