Skip to content

Commit 9350af1

Browse files
committed
[comp] Restore FirstClassCallableRector and make it explicitly deprecated, to ease transition
1 parent bd7bb2a commit 9350af1

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

phpstan.neon

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,3 +433,12 @@ parameters:
433433
- rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php
434434
- rules/Php81/Enum/AttributeName.php
435435

436+
# deprecated rule
437+
- '#Rule Rector\\Php81\\Rector\\Array_\\FirstClassCallableRector must implements Rector\\VersionBonding\\Contract\\MinPhpVersionInterface#'
438+
- '#Register "Rector\\Php81\\Rector\\Array_\\FirstClassCallableRector" service to "php81\.php" config set#'
439+
- '#Access to constant on deprecated class Rector\\Php81\\Rector\\Array_\\FirstClassCallableRector#'
440+
-
441+
message: '#Only abstract classes can be extended#'
442+
path: rules/Php81/Rector/Array_/FirstClassCallableRector.php
443+
444+

rector.php

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

33
declare(strict_types=1);
44

5-
use Rector\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector;
65
use Rector\CodingStyle\Rector\String_\UseClassKeywordForClassNameResolutionRector;
76
use Rector\Config\RectorConfig;
87
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
@@ -42,9 +41,6 @@
4241
->withImportNames(removeUnusedImports: true)
4342
->withRules([RemoveRefactorDuplicatedNodeInstanceCheckRector::class, AddSeeTestAnnotationRector::class])
4443
->withSkip([
45-
// testing skip of deprecated class
46-
FunctionLikeToFirstClassCallableRector::class,
47-
4844
StringClassNameToClassConstantRector::class,
4945
// tests
5046
'*/Fixture*',

rules/Php81/Rector/Array_/ArrayToFirstClassCallableRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @see RFC https://wiki.php.net/rfc/first_class_callable_syntax
3232
* @see \Rector\Tests\Php81\Rector\Array_\ArrayToFirstClassCallableRector\ArrayToFirstClassCallableRectorTest
3333
*/
34-
final class ArrayToFirstClassCallableRector extends AbstractRector implements MinPhpVersionInterface
34+
class ArrayToFirstClassCallableRector extends AbstractRector implements MinPhpVersionInterface
3535
{
3636
public function __construct(
3737
private readonly ArrayCallableMethodMatcher $arrayCallableMethodMatcher,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Php81\Rector\Array_;
6+
7+
use PhpParser\Node;
8+
use PhpParser\Node\Expr\MethodCall;
9+
use PhpParser\Node\Expr\StaticCall;
10+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
11+
use Rector\Exception\ShouldNotHappenException;
12+
13+
/**
14+
* @deprecated Renamed to \Rector\Php81\Rector\Array_\ArrayToFirstClassCallableRector
15+
*/
16+
final class FirstClassCallableRector extends ArrayToFirstClassCallableRector implements DeprecatedInterface
17+
{
18+
public function refactor(Node $node): StaticCall|MethodCall|null
19+
{
20+
throw new ShouldNotHappenException(sprintf(
21+
'%s is deprecated and renamed to "%s". Use it instead.',
22+
self::class,
23+
ArrayToFirstClassCallableRector::class
24+
));
25+
}
26+
}

src/Skipper/SkipCriteriaResolver/SkippedClassResolver.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,25 @@
1515
final class SkippedClassResolver
1616
{
1717
/**
18-
* @var null|array<string, string[]|null>
18+
* @var null|array<class-string, string[]|null>
1919
*/
2020
private null|array $skippedClassesToFiles = null;
2121

2222
/**
23-
* @return array<DeprecatedInterface>
23+
* @return array<class-string<DeprecatedInterface>>
2424
*/
2525
public function resolveDeprecatedSkippedClasses(): array
2626
{
2727
$skippedClassNames = array_keys($this->resolve());
2828

29-
return array_filter($skippedClassNames, function (string $class): bool {
30-
return is_a($class, DeprecatedInterface::class, true);
31-
});
29+
return array_filter(
30+
$skippedClassNames,
31+
fn (string $class): bool => is_a($class, DeprecatedInterface::class, true)
32+
);
3233
}
3334

3435
/**
35-
* @return array<string, string[]|null>
36+
* @return array<class-string, string[]|null>
3637
*/
3738
public function resolve(): array
3839
{

0 commit comments

Comments
 (0)