Skip to content

Commit e2ce6b7

Browse files
committed
style(symfony): fix cs-fixer + phpstan on upgrade-filter
php-cs-fixer: global \is_callable, phpdoc @throws/@return order. phpstan: ?-> on getMethod() flagged never-null by parser stub -> explicit constructor guard (also runtime-safe; getMethod can be null).
1 parent 44add4d commit e2ce6b7

6 files changed

Lines changed: 27 additions & 24 deletions

File tree

src/Symfony/Bundle/Command/Upgrade/UpgradeApiFilterMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function map(string $filterClass, ?string $strategy = null, ?string $prop
3636
}
3737

3838
$shortName = substr($filterClass, \strlen($namespace) + 1);
39-
$canonical = fn (string $name): string => $namespace.'\\'.$name;
39+
$canonical = static fn (string $name): string => $namespace.'\\'.$name;
4040

4141
return match ($shortName) {
4242
'BooleanFilter' => new UpgradeApiFilterMapping($canonical('ExactFilter'), castToNativeType: true, nativeType: 'bool'),

src/Symfony/Bundle/Command/Upgrade/UpgradeApiFilterParameter.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
final readonly class UpgradeApiFilterParameter
2222
{
2323
/**
24-
* @param string $key the parameter key (query string name)
25-
* @param string $filterClass canonical replacement filter FQCN to instantiate
26-
* @param string|null $property explicit property when it differs from $key
27-
* @param string|null $nativeType scalar native type hint (bool|int|float|string), null to omit
28-
* @param bool $castToNativeType whether the QueryParameter should coerce the raw value
29-
* @param string|null $filterContext filter-specific config carried by the QueryParameter (e.g. the
30-
* DateFilter null-management mode), null to omit
31-
* @param bool $caseSensitive emit `caseSensitive: true` on the search filter (case-sensitive
32-
* strategy); the new search filters are case-insensitive by default
33-
* @param array<string, mixed> $arguments constructor arguments to pass to the (kept) filter, named
24+
* @param string $key the parameter key (query string name)
25+
* @param string $filterClass canonical replacement filter FQCN to instantiate
26+
* @param string|null $property explicit property when it differs from $key
27+
* @param string|null $nativeType scalar native type hint (bool|int|float|string), null to omit
28+
* @param bool $castToNativeType whether the QueryParameter should coerce the raw value
29+
* @param string|null $filterContext filter-specific config carried by the QueryParameter (e.g. the
30+
* DateFilter null-management mode), null to omit
31+
* @param bool $caseSensitive emit `caseSensitive: true` on the search filter (case-sensitive
32+
* strategy); the new search filters are case-insensitive by default
33+
* @param array<string, mixed> $arguments constructor arguments to pass to the (kept) filter, named
3434
*/
3535
public function __construct(
3636
public string $key,

src/Symfony/Bundle/Command/Upgrade/UpgradeApiFilterResolver.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ public function __construct(
5252

5353
/**
5454
* @param list<array{filter: FilterInterface, filterClass: class-string, arguments: array<string, mixed>}> $filters
55-
* one entry per `#[ApiFilter]` declaration (keyed by service id upstream so that two
56-
* instances of the same filter class are kept distinct)
55+
* one entry per `#[ApiFilter]` declaration (keyed by service id upstream so that two
56+
* instances of the same filter class are kept distinct)
5757
* @param list<FilterInterface> $reservedFilters in-place service filters (the resource `filters:` array) whose query keys must
58-
* not be re-migrated: an #[ApiFilter] mapping onto one of these keys would shadow it
59-
*
60-
* @return list<UpgradeApiFilterParameter>
58+
* not be re-migrated: an #[ApiFilter] mapping onto one of these keys would shadow it
6159
*
6260
* @throws UpgradeApiFilterCollisionException when two filters map to the same parameter key, or an
6361
* #[ApiFilter] key collides with an in-place service filter
62+
*
63+
* @return list<UpgradeApiFilterParameter>
6464
*/
6565
public function resolve(string $resourceClass, array $filters, array $reservedFilters = []): array
6666
{
@@ -81,7 +81,7 @@ public function resolve(string $resourceClass, array $filters, array $reservedFi
8181

8282
// The mode of a DateFilter (include/exclude null) lives in the constructor `properties` map
8383
// as the value, never in getDescription(); read it straight from the filter instance.
84-
$rawProperties = is_callable([$filter, 'getProperties']) ? ($filter->getProperties() ?? []) : [];
84+
$rawProperties = \is_callable([$filter, 'getProperties']) ? ($filter->getProperties() ?? []) : [];
8585

8686
foreach ($this->group($description) as $key => $info) {
8787
if (isset($seenKeys[$key])) {
@@ -167,7 +167,7 @@ private function group(array $description): array
167167
*/
168168
private function assertNoNameConversion(FilterInterface $filter, array $description): void
169169
{
170-
$nameConverter = is_callable([$filter, 'getNameConverter']) ? $filter->getNameConverter() : null;
170+
$nameConverter = \is_callable([$filter, 'getNameConverter']) ? $filter->getNameConverter() : null;
171171
if (!$nameConverter instanceof NameConverterInterface) {
172172
return;
173173
}

src/Symfony/Bundle/Command/Upgrade/UpgradeApiFilterVisitor.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class UpgradeApiFilterVisitor extends NodeVisitorAbstract
4242
private array $removedFilterShortNames = [];
4343

4444
/**
45-
* @param string $className FQCN of the resource class to transform
45+
* @param string $className FQCN of the resource class to transform
4646
* @param list<UpgradeApiFilterParameter> $parameters resolved QueryParameter targets to inject
4747
*/
4848
public function __construct(
@@ -83,8 +83,11 @@ private function removeApiFilterAttributes(Node\Stmt\Class_ $node): void
8383
$this->stripApiFilter($property);
8484
}
8585

86-
foreach ($node->getMethod('__construct')?->params ?? [] as $param) {
87-
$this->stripApiFilter($param);
86+
$constructor = $node->getMethod('__construct');
87+
if (null !== $constructor) {
88+
foreach ($constructor->params as $param) {
89+
$this->stripApiFilter($param);
90+
}
8891
}
8992
}
9093

src/Symfony/Bundle/Command/UpgradeApiFilterCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private function reservedFilters(string $resourceClass): array
194194
}
195195

196196
/**
197-
* @param list<\ApiPlatform\Symfony\Bundle\Command\Upgrade\UpgradeApiFilterParameter> $parameters
197+
* @param list<Upgrade\UpgradeApiFilterParameter> $parameters
198198
*/
199199
private function transform(string $code, string $resourceClass, array $parameters): string
200200
{

src/Symfony/Tests/Bundle/Command/UpgradeApiFilterResolverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
final class UpgradeApiFilterResolverTest extends TestCase
3838
{
3939
/**
40-
* @param array<string, Type> $nativeTypes property name => native type used to detect relations
41-
* @param list<string> $resourceClasses class names the resolver should treat as API resources
40+
* @param array<string, Type> $nativeTypes property name => native type used to detect relations
41+
* @param list<string> $resourceClasses class names the resolver should treat as API resources
4242
*/
4343
private function resolver(array $nativeTypes = [], array $resourceClasses = []): UpgradeApiFilterResolver
4444
{

0 commit comments

Comments
 (0)