Skip to content

Commit 4588da4

Browse files
committed
Update PHP-CS-Fixer to use PHP 8.0 migration rules
Changed from @PHP71Migration:risky to @PHP80Migration:risky to enable PHP 8.0+ coding standards and modernizations. This automatically converts traditional closures to arrow functions where applicable, resulting in cleaner, more concise code. Changes applied: - Updated .php-cs-fixer.dist.php configuration - Converted 7 closures to arrow functions (fn) - Removed outdated PHP 7.3 compatibility comment Benefits: - 20 lines of code removed - More modern PHP 8.0+ syntax - Better alignment with minimum PHP version requirement
1 parent 51de2b5 commit 4588da4

File tree

8 files changed

+12
-32
lines changed

8 files changed

+12
-32
lines changed

.php-cs-fixer.dist.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'@PER-CS' => true,
1313
'@Symfony' => true,
1414
'@Symfony:risky' => true,
15-
'@PHP71Migration:risky' => true,
15+
'@PHP80Migration:risky' => true,
1616
'@PSR2' => true,
1717
'@DoctrineAnnotation' => true,
1818
'array_syntax' => ['syntax' => 'short'],
@@ -24,7 +24,7 @@
2424
'modernize_types_casting' => true, // Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operator.
2525
'multiline_whitespace_before_semicolons' => true, // Forbid multi-line whitespace before the closing semicolon or move the semicolon to the new line for chained calls.
2626
'no_unreachable_default_argument_value' => true, // In function arguments there must not be arguments with default values before non-default ones.
27-
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true], // To avoid problems of compatibility with the old php-cs-fixer version used on PHP 7.3
27+
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
2828
'no_useless_else' => true,
2929
'no_useless_return' => true,
3030
'ordered_class_elements' => true, // Orders the elements of classes/interfaces/traits.

src/Analyzer/ClassDescription.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ public function hasAttribute(string $pattern): bool
196196
{
197197
return array_reduce(
198198
$this->attributes,
199-
static function (bool $carry, FullyQualifiedClassName $attribute) use ($pattern): bool {
200-
return $carry || $attribute->matches($pattern);
201-
},
199+
static fn (bool $carry, FullyQualifiedClassName $attribute): bool => $carry || $attribute->matches($pattern),
202200
false
203201
);
204202
}

src/Expression/ForClasses/Implement.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public function evaluate(ClassDescription $theClass, Violations $violations, str
4040

4141
$interface = $this->interface;
4242
$interfaces = $theClass->getInterfaces();
43-
$implements = function (FullyQualifiedClassName $FQCN) use ($interface): bool {
44-
return $FQCN->matches($interface);
45-
};
43+
$implements = fn (FullyQualifiedClassName $FQCN): bool => $FQCN->matches($interface);
4644

4745
if (0 === \count(array_filter($interfaces, $implements))) {
4846
$violation = Violation::create(

src/Expression/ForClasses/NotHaveDependencyOutsideNamespace.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public function describe(ClassDescription $theClass, string $because): Descripti
3636
public function evaluate(ClassDescription $theClass, Violations $violations, string $because): void
3737
{
3838
$namespace = $this->namespace;
39-
$depends = function (ClassDependency $dependency) use ($namespace): bool {
40-
return !$dependency->getFQCN()->matches($namespace);
41-
};
39+
$depends = fn (ClassDependency $dependency): bool => !$dependency->getFQCN()->matches($namespace);
4240

4341
$dependencies = $theClass->getDependencies();
4442
$externalDeps = array_filter($dependencies, $depends);

src/Expression/ForClasses/NotImplement.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public function evaluate(ClassDescription $theClass, Violations $violations, str
4040

4141
$interface = $this->interface;
4242
$interfaces = $theClass->getInterfaces();
43-
$implements = function (FullyQualifiedClassName $FQCN) use ($interface): bool {
44-
return $FQCN->matches($interface);
45-
};
43+
$implements = fn (FullyQualifiedClassName $FQCN): bool => $FQCN->matches($interface);
4644

4745
if (\count(array_filter($interfaces, $implements)) > 0) {
4846
$violation = Violation::create(

src/RuleBuilders/Architecture/Architecture.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ public function rules(string $because = 'of component architecture'): iterable
9090
$forbiddenComponents = array_diff($layerNames, [$name], $this->allowedDependencies[$name]);
9191

9292
if (!empty($forbiddenComponents)) {
93-
$forbiddenSelectors = array_values(array_map(function (string $componentName): string {
94-
return $this->componentSelectors[$componentName];
95-
}, $forbiddenComponents));
93+
$forbiddenSelectors = array_values(array_map(fn (string $componentName): string => $this->componentSelectors[$componentName], $forbiddenComponents));
9694

9795
yield Rule::allClasses()
9896
->that(new ResideInOneOfTheseNamespaces($selector))
@@ -105,9 +103,7 @@ public function rules(string $because = 'of component architecture'): iterable
105103
continue;
106104
}
107105

108-
$allowedDependencies = array_values(array_map(function (string $componentName): string {
109-
return $this->componentSelectors[$componentName];
110-
}, $this->componentDependsOnlyOnTheseNamespaces[$name]));
106+
$allowedDependencies = array_values(array_map(fn (string $componentName): string => $this->componentSelectors[$componentName], $this->componentDependsOnlyOnTheseNamespaces[$name]));
111107

112108
yield Rule::allClasses()
113109
->that(new ResideInOneOfTheseNamespaces($selector))

src/Rules/Violations.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ public static function fromJson(string $json): self
2727

2828
$instance = new self();
2929

30-
$instance->violations = array_map(function (array $json): Violation {
31-
return Violation::fromJson($json);
32-
}, $json['violations']);
30+
$instance->violations = array_map(fn (array $json): Violation => Violation::fromJson($json), $json['violations']);
3331

3432
return $instance;
3533
}
@@ -113,9 +111,7 @@ public function remove(self $violations, bool $ignoreBaselineLinenumbers = false
113111

114112
public function sort(): void
115113
{
116-
usort($this->violations, static function (Violation $v1, Violation $v2): int {
117-
return $v1 <=> $v2;
118-
});
114+
usort($this->violations, static fn (Violation $v1, Violation $v2): int => $v1 <=> $v2);
119115
}
120116

121117
public function jsonSerialize(): array

tests/Unit/ClassSetTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ public function test_can_exclude_files_or_directories(): void
5454
'View/UserView.php',
5555
];
5656

57-
$actual = array_values(array_map(function ($item) {
58-
return $item->getRelativePathname();
59-
}, iterator_to_array($set)));
57+
$actual = array_values(array_map(fn ($item) => $item->getRelativePathname(), iterator_to_array($set)));
6058

6159
self::assertEquals($expected, $actual);
6260
}
@@ -83,9 +81,7 @@ public function test_can_exclude_glob_patterns(): void
8381
'View/UserView.php',
8482
];
8583

86-
$actual = array_values(array_map(function ($item) {
87-
return $item->getRelativePathname();
88-
}, iterator_to_array($set)));
84+
$actual = array_values(array_map(fn ($item) => $item->getRelativePathname(), iterator_to_array($set)));
8985

9086
self::assertEquals($expected, $actual);
9187
}

0 commit comments

Comments
 (0)