Skip to content

Commit 942a891

Browse files
committed
Updated Rector to commit 4c3f17579bd9e78efb187063c12f9aba86fcd535
rectorphp/rector-src@4c3f175 [Php85] Add ArrayFirstLastRector (#6900)
1 parent 3ee96a4 commit 942a891

11 files changed

Lines changed: 117 additions & 3 deletions

File tree

config/set/level/up-to-php85.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace RectorPrefix202505;
5+
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
use Rector\Set\ValueObject\SetList;
9+
return static function (RectorConfig $rectorConfig) : void {
10+
$rectorConfig->sets([SetList::PHP_85, LevelSetList::UP_TO_PHP_84]);
11+
};

config/set/php85.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace RectorPrefix202505;
5+
6+
use Rector\Config\RectorConfig;
7+
use Rector\Php85\Rector\ArrayDimFetch\ArrayFirstLastRector;
8+
return static function (RectorConfig $rectorConfig) : void {
9+
$rectorConfig->rules([ArrayFirstLastRector::class]);
10+
};
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace Rector\Php85\Rector\ArrayDimFetch;
5+
6+
use PhpParser\Node;
7+
use PhpParser\Node\Expr\ArrayDimFetch;
8+
use PhpParser\Node\Expr\FuncCall;
9+
use Rector\Rector\AbstractRector;
10+
use Rector\ValueObject\PhpVersionFeature;
11+
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
12+
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
13+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
14+
/**
15+
* @see https://php.watch/versions/8.5/array_first-array_last
16+
* @see \Rector\Tests\Php85\Rector\ArrayDimFetch\ArrayFirstLastRector\ArrayFirstLastRectorTest
17+
*/
18+
final class ArrayFirstLastRector extends AbstractRector implements MinPhpVersionInterface
19+
{
20+
/**
21+
* @var string
22+
*/
23+
private const ARRAY_KEY_FIRST = 'array_key_first';
24+
/**
25+
* @var string
26+
*/
27+
private const ARRAY_KEY_LAST = 'array_key_last';
28+
public function getRuleDefinition() : RuleDefinition
29+
{
30+
return new RuleDefinition('Make use of array_first() and array_last()', [new CodeSample(<<<'CODE_SAMPLE'
31+
echo $array[array_key_first($array)];
32+
echo $array[array_key_last($array)];
33+
CODE_SAMPLE
34+
, <<<'CODE_SAMPLE'
35+
echo array_first($array);
36+
echo array_last($array;
37+
CODE_SAMPLE
38+
)]);
39+
}
40+
/**
41+
* @return array<class-string<Node>>
42+
*/
43+
public function getNodeTypes() : array
44+
{
45+
return [ArrayDimFetch::class];
46+
}
47+
/**
48+
* @param ArrayDimFetch $node
49+
*/
50+
public function refactor(Node $node) : ?FuncCall
51+
{
52+
if (!$node->dim instanceof FuncCall) {
53+
return null;
54+
}
55+
if (!$this->isNames($node->dim, [self::ARRAY_KEY_FIRST, self::ARRAY_KEY_LAST])) {
56+
return null;
57+
}
58+
if ($node->dim->isFirstClassCallable()) {
59+
return null;
60+
}
61+
if (\count($node->dim->getArgs()) !== 1) {
62+
return null;
63+
}
64+
if (!$this->nodeComparator->areNodesEqual($node->var, $node->dim->getArgs()[0]->value)) {
65+
return null;
66+
}
67+
$functionName = $this->isName($node->dim, self::ARRAY_KEY_FIRST) ? 'array_first' : 'array_last';
68+
return $this->nodeFactory->createFuncCall($functionName, [$node->var]);
69+
}
70+
public function provideMinPhpVersion() : int
71+
{
72+
return PhpVersionFeature::ARRAY_FIRST_LAST;
73+
}
74+
}

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = 'ce8575f35a2ea096e91223347074542c1e603742';
22+
public const PACKAGE_VERSION = '4c3f17579bd9e78efb187063c12f9aba86fcd535';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-05-12 17:08:54';
27+
public const RELEASE_DATE = '2025-05-13 11:25:55';
2828
/**
2929
* @var int
3030
*/

src/Set/SetProvider/PHPSetProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ final class PHPSetProvider implements SetProviderInterface
1414
*/
1515
public function provide() : array
1616
{
17-
return [new Set(SetGroup::PHP, 'PHP 5.3', __DIR__ . '/../../../config/set/php53.php'), new Set(SetGroup::PHP, 'PHP 5.4', __DIR__ . '/../../../config/set/php54.php'), new Set(SetGroup::PHP, 'PHP 5.5', __DIR__ . '/../../../config/set/php55.php'), new Set(SetGroup::PHP, 'PHP 5.6', __DIR__ . '/../../../config/set/php56.php'), new Set(SetGroup::PHP, 'PHP 7.0', __DIR__ . '/../../../config/set/php70.php'), new Set(SetGroup::PHP, 'PHP 7.1', __DIR__ . '/../../../config/set/php71.php'), new Set(SetGroup::PHP, 'PHP 7.2', __DIR__ . '/../../../config/set/php72.php'), new Set(SetGroup::PHP, 'PHP 7.3', __DIR__ . '/../../../config/set/php73.php'), new Set(SetGroup::PHP, 'PHP 7.4', __DIR__ . '/../../../config/set/php74.php'), new Set(SetGroup::PHP, 'PHP 8.0', __DIR__ . '/../../../config/set/php80.php'), new Set(SetGroup::PHP, 'PHP 8.1', __DIR__ . '/../../../config/set/php81.php'), new Set(SetGroup::PHP, 'PHP 8.2', __DIR__ . '/../../../config/set/php82.php'), new Set(SetGroup::PHP, 'PHP 8.3', __DIR__ . '/../../../config/set/php83.php'), new Set(SetGroup::PHP, 'PHP 8.4', __DIR__ . '/../../../config/set/php84.php'), new Set(SetGroup::PHP, 'Polyfills', __DIR__ . '/../../../config/set/php-polyfills.php')];
17+
return [new Set(SetGroup::PHP, 'PHP 5.3', __DIR__ . '/../../../config/set/php53.php'), new Set(SetGroup::PHP, 'PHP 5.4', __DIR__ . '/../../../config/set/php54.php'), new Set(SetGroup::PHP, 'PHP 5.5', __DIR__ . '/../../../config/set/php55.php'), new Set(SetGroup::PHP, 'PHP 5.6', __DIR__ . '/../../../config/set/php56.php'), new Set(SetGroup::PHP, 'PHP 7.0', __DIR__ . '/../../../config/set/php70.php'), new Set(SetGroup::PHP, 'PHP 7.1', __DIR__ . '/../../../config/set/php71.php'), new Set(SetGroup::PHP, 'PHP 7.2', __DIR__ . '/../../../config/set/php72.php'), new Set(SetGroup::PHP, 'PHP 7.3', __DIR__ . '/../../../config/set/php73.php'), new Set(SetGroup::PHP, 'PHP 7.4', __DIR__ . '/../../../config/set/php74.php'), new Set(SetGroup::PHP, 'PHP 8.0', __DIR__ . '/../../../config/set/php80.php'), new Set(SetGroup::PHP, 'PHP 8.1', __DIR__ . '/../../../config/set/php81.php'), new Set(SetGroup::PHP, 'PHP 8.2', __DIR__ . '/../../../config/set/php82.php'), new Set(SetGroup::PHP, 'PHP 8.3', __DIR__ . '/../../../config/set/php83.php'), new Set(SetGroup::PHP, 'PHP 8.4', __DIR__ . '/../../../config/set/php84.php'), new Set(SetGroup::PHP, 'PHP 8.5', __DIR__ . '/../../../config/set/php85.php'), new Set(SetGroup::PHP, 'Polyfills', __DIR__ . '/../../../config/set/php-polyfills.php')];
1818
}
1919
}

src/Set/ValueObject/LevelSetList.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
*/
99
final class LevelSetList
1010
{
11+
/**
12+
* @var string
13+
*/
14+
public const UP_TO_PHP_85 = __DIR__ . '/../../../config/set/level/up-to-php85.php';
1115
/**
1216
* @var string
1317
*/

src/Set/ValueObject/SetList.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ final class SetList
103103
* @var string
104104
*/
105105
public const PHP_84 = __DIR__ . '/../../../config/set/php84.php';
106+
/**
107+
* @var string
108+
*/
109+
public const PHP_85 = __DIR__ . '/../../../config/set/php85.php';
106110
/**
107111
* @var string
108112
*/

src/ValueObject/PhpVersion.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ final class PhpVersion
6868
* @var int
6969
*/
7070
public const PHP_84 = 80400;
71+
/**
72+
* @var int
73+
*/
74+
public const PHP_85 = 80500;
7175
/**
7276
* @var int
7377
*/

src/ValueObject/PhpVersionFeature.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ final class PhpVersionFeature
240240
* @var int
241241
*/
242242
public const ARRAY_KEY_FIRST_LAST = \Rector\ValueObject\PhpVersion::PHP_73;
243+
/**
244+
* @var int
245+
* @see https://php.watch/versions/8.5/array_first-array_last
246+
*/
247+
public const ARRAY_FIRST_LAST = \Rector\ValueObject\PhpVersion::PHP_85;
243248
/**
244249
* @var int
245250
*/

vendor/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,7 @@
20612061
'Rector\\Php84\\Rector\\FuncCall\\RoundingModeEnumRector' => $baseDir . '/rules/Php84/Rector/FuncCall/RoundingModeEnumRector.php',
20622062
'Rector\\Php84\\Rector\\MethodCall\\NewMethodCallWithoutParenthesesRector' => $baseDir . '/rules/Php84/Rector/MethodCall/NewMethodCallWithoutParenthesesRector.php',
20632063
'Rector\\Php84\\Rector\\Param\\ExplicitNullableParamTypeRector' => $baseDir . '/rules/Php84/Rector/Param/ExplicitNullableParamTypeRector.php',
2064+
'Rector\\Php85\\Rector\\ArrayDimFetch\\ArrayFirstLastRector' => $baseDir . '/rules/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector.php',
20642065
'Rector\\PhpAttribute\\AnnotationToAttributeMapper' => $baseDir . '/src/PhpAttribute/AnnotationToAttributeMapper.php',
20652066
'Rector\\PhpAttribute\\AnnotationToAttributeMapper\\ArrayAnnotationToAttributeMapper' => $baseDir . '/src/PhpAttribute/AnnotationToAttributeMapper/ArrayAnnotationToAttributeMapper.php',
20662067
'Rector\\PhpAttribute\\AnnotationToAttributeMapper\\ArrayItemNodeAnnotationToAttributeMapper' => $baseDir . '/src/PhpAttribute/AnnotationToAttributeMapper/ArrayItemNodeAnnotationToAttributeMapper.php',

0 commit comments

Comments
 (0)