Skip to content

Commit 230e9ee

Browse files
authored
Utilize array_last() (#4504)
1 parent 8c871fc commit 230e9ee

19 files changed

+204
-34
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ jobs:
109109
uses: "shivammathur/setup-php@v2"
110110
with:
111111
coverage: "none"
112-
php-version: "8.3"
112+
php-version: "8.5"
113113

114114
- uses: "ramsey/composer-install@v3"
115115

build/composer-dependency-analyser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
'symfony/polyfill-php80',
1313
'symfony/polyfill-php81',
1414
'symfony/polyfill-php83',
15+
'symfony/polyfill-php84',
16+
'symfony/polyfill-php85',
1517
];
1618

1719
$pinnedToSupportPhp72 = [

compiler/build/scoper.inc.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
'../../stubs',
1717
'../../vendor/jetbrains/phpstorm-stubs',
1818
'../../vendor/phpstan/php-8-stubs/stubs',
19+
// when adding new polyfills, don't forget to also append them in 'exclude-namespaces' below
1920
'../../vendor/symfony/polyfill-php80',
2021
'../../vendor/symfony/polyfill-php81',
2122
'../../vendor/symfony/polyfill-php83',
23+
'../../vendor/symfony/polyfill-php84',
24+
'../../vendor/symfony/polyfill-php85',
2225
'../../vendor/symfony/polyfill-mbstring',
2326
'../../vendor/symfony/polyfill-intl-normalizer',
2427
'../../vendor/symfony/polyfill-intl-grapheme',
@@ -246,6 +249,8 @@ function (string $filePath, string $prefix, string $content): string {
246249
'Symfony\Polyfill\Php80',
247250
'Symfony\Polyfill\Php81',
248251
'Symfony\Polyfill\Php83',
252+
'Symfony\Polyfill\Php84',
253+
'Symfony\Polyfill\Php85',
249254
'Symfony\Polyfill\Mbstring',
250255
'Symfony\Polyfill\Intl\Normalizer',
251256
'Symfony\Polyfill\Intl\Grapheme',

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
"symfony/polyfill-php80": "^1.23",
4848
"symfony/polyfill-php81": "^1.27",
4949
"symfony/polyfill-php83": "^1.33",
50+
"symfony/polyfill-php84": "^1.33",
51+
"symfony/polyfill-php85": "^1.33",
5052
"symfony/process": "^5.4.3",
5153
"symfony/service-contracts": "^2.5.0",
5254
"symfony/string": "^5.4.3"

composer.lock

Lines changed: 161 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Analyser/MutatingScope.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,7 +3779,7 @@ private function enterAnonymousFunctionWithoutReflection(
37793779
if (isset($callableParameters[$i])) {
37803780
$parameterType = self::intersectButNotNever($parameterType, $callableParameters[$i]->getType());
37813781
} elseif (count($callableParameters) > 0) {
3782-
$lastParameter = $callableParameters[count($callableParameters) - 1];
3782+
$lastParameter = array_last($callableParameters);
37833783
if ($lastParameter->isVariadic()) {
37843784
$parameterType = self::intersectButNotNever($parameterType, $lastParameter->getType());
37853785
} else {
@@ -3972,7 +3972,7 @@ private function enterArrowFunctionWithoutReflection(Expr\ArrowFunction $arrowFu
39723972
if (isset($callableParameters[$i])) {
39733973
$parameterType = self::intersectButNotNever($parameterType, $callableParameters[$i]->getType());
39743974
} elseif (count($callableParameters) > 0) {
3975-
$lastParameter = $callableParameters[count($callableParameters) - 1];
3975+
$lastParameter = array_last($callableParameters);
39763976
if ($lastParameter->isVariadic()) {
39773977
$parameterType = self::intersectButNotNever($parameterType, $lastParameter->getType());
39783978
} else {

src/Analyser/NodeScopeResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ private function processStmtNode(
14811481

14821482
$bodyScope = $initScope;
14831483
$isIterableAtLeastOnce = TrinaryLogic::createYes();
1484-
$lastCondExpr = $stmt->cond[count($stmt->cond) - 1] ?? null;
1484+
$lastCondExpr = array_last($stmt->cond) ?? null;
14851485
foreach ($stmt->cond as $condExpr) {
14861486
$condResult = $this->processExprNode($stmt, $condExpr, $bodyScope, static function (): void {
14871487
}, ExpressionContext::createDeep());
@@ -5239,7 +5239,7 @@ private function processArgs(
52395239
}
52405240
$parameter = $parameters[$i];
52415241
} elseif (count($parameters) > 0 && $parametersAcceptor->isVariadic()) {
5242-
$lastParameter = $parameters[count($parameters) - 1];
5242+
$lastParameter = array_last($parameters);
52435243
$assignByReference = $lastParameter->passedByReference()->createsNewVariable();
52445244
$parameterType = $lastParameter->getType();
52455245

@@ -5432,7 +5432,7 @@ private function processArgs(
54325432
if (isset($parameters[$i])) {
54335433
$currentParameter = $parameters[$i];
54345434
} elseif (count($parameters) > 0 && $parametersAcceptor->isVariadic()) {
5435-
$currentParameter = $parameters[count($parameters) - 1];
5435+
$currentParameter = array_last($parameters);
54365436
}
54375437

54385438
if ($currentParameter !== null) {

src/Analyser/TypeSpecifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ private function specifyTypesFromAsserts(TypeSpecifierContext $context, Expr\Cal
15171517
} elseif (isset($parameters[$i])) {
15181518
$paramName = $parameters[$i]->getName();
15191519
} elseif (count($parameters) > 0 && $parametersAcceptor->isVariadic()) {
1520-
$lastParameter = $parameters[count($parameters) - 1];
1520+
$lastParameter = array_last($parameters);
15211521
$paramName = $lastParameter->getName();
15221522
} else {
15231523
continue;

src/Fixable/PhpPrinter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function pCommaSeparated(array $nodes): string
2424
if (count($nodes) === 0) {
2525
return $result;
2626
}
27-
$last = $nodes[count($nodes) - 1];
27+
$last = array_last($nodes);
2828

2929
$trailingComma = $last->getAttribute(self::FUNC_ARGS_TRAILING_COMMA_ATTRIBUTE);
3030
if ($trailingComma === false) {

src/Parser/LastConditionVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function enterNode(Node $node): ?Node
8787
}
8888

8989
$if = $statements[$statementCount - 2];
90-
$cond = count($if->elseifs) > 0 ? $if->elseifs[count($if->elseifs) - 1]->cond : $if->cond;
90+
$cond = count($if->elseifs) > 0 ? array_last($if->elseifs)->cond : $if->cond;
9191
$cond->setAttribute(self::ATTRIBUTE_NAME, true);
9292
}
9393

0 commit comments

Comments
 (0)