Skip to content

Commit 4ba2b8f

Browse files
committed
apply PHP 8.4 polyfills
1 parent 79dc845 commit 4ba2b8f

19 files changed

Lines changed: 47 additions & 132 deletions

File tree

‎config/set/php-polyfills.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Rector\Php83\Rector\BooleanAnd\JsonValidateRector;
1414
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
1515
use Rector\Php84\Rector\Class_\DeprecatedAnnotationToDeprecatedAttributeRector;
16+
use Rector\Php84\Rector\Foreach_\ForeachToArrayAllRector;
1617
use Rector\Php84\Rector\Foreach_\ForeachToArrayAnyRector;
1718
use Rector\Php84\Rector\Foreach_\ForeachToArrayFindKeyRector;
1819
use Rector\Php84\Rector\Foreach_\ForeachToArrayFindRector;
@@ -36,7 +37,7 @@
3637
AddOverrideAttributeToOverriddenMethodsRector::class,
3738

3839
// PHP 8.4
39-
\Rector\Php84\Rector\Foreach_\ForeachToArrayAllRector::class,
40+
ForeachToArrayAllRector::class,
4041
ForeachToArrayAnyRector::class,
4142
ForeachToArrayFindRector::class,
4243
ForeachToArrayFindKeyRector::class,

‎rules/DeadCode/NodeAnalyzer/IsClassMethodUsedAnalyzer.php‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,10 @@ private function doesMethodExistInTrait(ClassMethod $classMethod, string $classM
167167

168168
$traits = $this->astResolver->parseClassReflectionTraits($classReflection);
169169
$className = $classReflection->getName();
170-
171-
foreach ($traits as $trait) {
172-
if ($this->isUsedByTrait($trait, $classMethodName, $className)) {
173-
return true;
174-
}
175-
}
176-
177-
return false;
170+
return array_any(
171+
$traits,
172+
fn (Trait_ $trait): bool => $this->isUsedByTrait($trait, $classMethodName, $className)
173+
);
178174
}
179175

180176
private function isUsedByTrait(Trait_ $trait, string $classMethodName, string $className): bool

‎rules/DeadCode/Rector/If_/RemoveTypedPropertyDeadInstanceOfRector.php‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,6 @@ private function isInPropertyPromotedParams(Class_ $class, PropertyFetch|StaticP
208208
/** @var string $propertyName */
209209
$propertyName = $this->getName($propertyFetch);
210210
$params = $this->promotedPropertyResolver->resolveFromClass($class);
211-
212-
foreach ($params as $param) {
213-
if ($this->isName($param, $propertyName)) {
214-
return true;
215-
}
216-
}
217-
218-
return false;
211+
return array_any($params, fn (Node $param): bool => $this->isName($param, $propertyName));
219212
}
220213
}

‎rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rector\Php55\Rector\String_;
66

7+
use Deprecated;
78
use PhpParser\Node;
89
use PhpParser\Node\Expr\ClassConstFetch;
910
use PhpParser\Node\Name\FullyQualified;
@@ -23,9 +24,7 @@
2324
*/
2425
final class StringClassNameToClassConstantRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface
2526
{
26-
/**
27-
* @deprecated since 2.2.12. Default behavior now.
28-
*/
27+
#[Deprecated(message: 'since 2.2.12. Default behavior now.')]
2928
public const string SHOULD_KEEP_PRE_SLASH = 'should_keep_pre_slash';
3029

3130
/**

‎rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,10 @@ public function hasPhpAttributes(
4848
Property | ClassLike | ClassMethod | Function_ | Param $node,
4949
array $attributeClasses
5050
): bool {
51-
foreach ($attributeClasses as $attributeClass) {
52-
if ($this->hasPhpAttribute($node, $attributeClass)) {
53-
return true;
54-
}
55-
}
56-
57-
return false;
51+
return array_any(
52+
$attributeClasses,
53+
fn (string $attributeClass): bool => $this->hasPhpAttribute($node, $attributeClass)
54+
);
5855
}
5956

6057
/**

‎rules/Php80/NodeResolver/SwitchExprsResolver.php‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,6 @@ private function isValidCase(Case_ $case): bool
160160

161161
private function areCasesValid(Switch_ $newSwitch): bool
162162
{
163-
foreach ($newSwitch->cases as $case) {
164-
if (! $this->isValidCase($case)) {
165-
return false;
166-
}
167-
}
168-
169-
return true;
163+
return array_all($newSwitch->cases, fn (Case_ $case): bool => $this->isValidCase($case));
170164
}
171165
}

‎rules/TypeDeclaration/NodeAnalyzer/NeverFuncCallAnalyzer.php‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ public function __construct(
2121

2222
public function hasNeverFuncCall(ClassMethod | Closure | Function_ $functionLike): bool
2323
{
24-
foreach ((array) $functionLike->stmts as $stmt) {
25-
if ($this->isWithNeverTypeExpr($stmt)) {
26-
return true;
27-
}
28-
}
29-
30-
return false;
24+
return array_any((array) $functionLike->stmts, fn (Stmt $stmt): bool => $this->isWithNeverTypeExpr($stmt));
3125
}
3226

3327
public function isWithNeverTypeExpr(Stmt $stmt, bool $withNativeNeverType = true): bool

‎rules/TypeDeclaration/NodeAnalyzer/StrictTypeSafetyChecker.php‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,7 @@ public function isFileStrictTypeSafe(FileNode $fileNode): bool
6262
}
6363

6464
$assigns = $this->betterNodeFinder->findInstanceOf($fileNode->stmts, Assign::class);
65-
foreach ($assigns as $assign) {
66-
if (! $this->isPropertyAssignSafe($assign)) {
67-
return false;
68-
}
69-
}
70-
71-
return true;
65+
return array_all($assigns, fn (Assign $assign): bool => $this->isPropertyAssignSafe($assign));
7266
}
7367

7468
private function isCallLikeSafe(CallLike $callLike): bool

‎src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,15 @@ public function hasByType(string $type): bool
168168
*/
169169
public function hasByTypes(array $types): bool
170170
{
171-
foreach ($types as $type) {
172-
if ($this->hasByType($type)) {
173-
return true;
174-
}
175-
}
176-
177-
return false;
171+
return array_any($types, fn (string $type): bool => $this->hasByType($type));
178172
}
179173

180174
/**
181175
* @param string[] $names
182176
*/
183177
public function hasByNames(array $names): bool
184178
{
185-
foreach ($names as $name) {
186-
if ($this->hasByName($name)) {
187-
return true;
188-
}
189-
}
190-
191-
return false;
179+
return array_any($names, fn (string $name): bool => $this->hasByName($name));
192180
}
193181

194182
public function hasByName(string $name): bool

‎src/Configuration/VendorMissAnalyseGuard.php‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ public function isVendorAnalyzed(array $filePaths): bool
2424
private function hasDowngradeSets(): bool
2525
{
2626
$registeredRectorSets = SimpleParameterProvider::provideArrayParameter(Option::REGISTERED_RECTOR_SETS);
27-
28-
foreach ($registeredRectorSets as $registeredRectorSet) {
29-
if (str_contains((string) $registeredRectorSet, 'downgrade-')) {
30-
return true;
31-
}
32-
}
33-
34-
return false;
27+
return array_any(
28+
$registeredRectorSets,
29+
fn ($registeredRectorSet): bool => str_contains((string) $registeredRectorSet, 'downgrade-')
30+
);
3531
}
3632

3733
/**

0 commit comments

Comments
 (0)