Skip to content

Commit fa7f417

Browse files
committed
[ci-review] Rector Rectify
1 parent a89913d commit fa7f417

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

‎utils/phpstan/src/Rule/CheaperGuardFirstRule.php‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
namespace Rector\Utils\PHPStan\Rule;
66

7+
use PhpParser\Node\Stmt\Else_;
8+
use PhpParser\Node\Expr\MethodCall;
9+
use PhpParser\Node\Expr\NullsafeMethodCall;
10+
use PhpParser\Node\Expr\StaticCall;
11+
use PhpParser\Node\Expr\FuncCall;
12+
use PhpParser\Node\Name;
713
use PhpParser\Node;
814
use PhpParser\Node\Expr\Assign;
915
use PhpParser\Node\Expr\CallLike;
@@ -33,17 +39,14 @@
3339
*/
3440
final class CheaperGuardFirstRule implements Rule
3541
{
36-
/**
37-
* @var string
38-
*/
39-
private const ERROR_MESSAGE = 'Cheap guard on line %d can run before the expensive call on line %d; move the early return up to bail before the costly analysis.';
42+
private const string ERROR_MESSAGE = 'Cheap guard on line %d can run before the expensive call on line %d; move the early return up to bail before the costly analysis.';
4043

4144
/**
4245
* Calls that trigger heavy analysis (type resolution, docblock parsing, file re-parsing).
4346
*
4447
* @var string[]
4548
*/
46-
private const EXPENSIVE_CALLS = [
49+
private const array EXPENSIVE_CALLS = [
4750
'getType',
4851
'getNativeType',
4952
'isObjectType',
@@ -57,18 +60,15 @@ final class CheaperGuardFirstRule implements Rule
5760
*
5861
* @var string[]
5962
*/
60-
private const CHEAP_CALLS = [
63+
private const array CHEAP_CALLS = [
6164
'isName',
6265
'isNames',
6366
'isFirstClassCallable',
6467
'in_array',
6568
'count',
6669
];
6770

68-
/**
69-
* @var string
70-
*/
71-
private const ABSTRACT_RECTOR_CLASS = 'Rector\Rector\AbstractRector';
71+
private const string ABSTRACT_RECTOR_CLASS = 'Rector\Rector\AbstractRector';
7272

7373
public function getNodeType(): string
7474
{
@@ -101,8 +101,9 @@ public function processNode(Node $node, Scope $scope): array
101101
}
102102

103103
$assignedVariableNames = $this->resolveAssignedVariableNames($stmts[$anchorIndex]);
104+
$counter = count($stmts);
104105

105-
for ($index = $anchorIndex + 1; $index < count($stmts); ++$index) {
106+
for ($index = $anchorIndex + 1; $index < $counter; ++$index) {
106107
$stmt = $stmts[$index];
107108

108109
if ($this->isPureBailGuard($stmt)) {
@@ -158,7 +159,7 @@ private function isPureBailGuard(Stmt $stmt): bool
158159
return false;
159160
}
160161

161-
if ($stmt->elseifs !== [] || $stmt->else !== null) {
162+
if ($stmt->elseifs !== [] || $stmt->else instanceof Else_) {
162163
return false;
163164
}
164165

@@ -238,12 +239,12 @@ private function containsCall(Node $node, array $callNames): bool
238239

239240
private function resolveCallName(CallLike $callLike): ?string
240241
{
241-
if ($callLike instanceof Node\Expr\MethodCall || $callLike instanceof Node\Expr\NullsafeMethodCall || $callLike instanceof Node\Expr\StaticCall) {
242+
if ($callLike instanceof MethodCall || $callLike instanceof NullsafeMethodCall || $callLike instanceof StaticCall) {
242243
return $callLike->name instanceof Identifier ? $callLike->name->toString() : null;
243244
}
244245

245-
if ($callLike instanceof Node\Expr\FuncCall) {
246-
return $callLike->name instanceof Node\Name ? $callLike->name->toString() : null;
246+
if ($callLike instanceof FuncCall) {
247+
return $callLike->name instanceof Name ? $callLike->name->toString() : null;
247248
}
248249

249250
return null;

0 commit comments

Comments
 (0)