1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace A17\Twill\Rector; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Route; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
use PhpParser\BuilderHelpers; |
8
|
|
|
use PhpParser\Node; |
9
|
|
|
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; |
10
|
|
|
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
11
|
|
|
|
12
|
|
|
class RenameViews extends LaravelAwareRectorRule |
13
|
|
|
{ |
14
|
|
|
public static $ROUTES = null; |
15
|
|
|
public $baseDir = null; |
16
|
|
|
|
17
|
|
|
public function getRuleDefinition(): RuleDefinition |
18
|
|
|
{ |
19
|
|
|
return new RuleDefinition( |
20
|
|
|
'Change usages of admin. views', [ |
21
|
|
|
new CodeSample( |
22
|
|
|
'view("admin.blocks.text");', |
23
|
|
|
'view("twill.blocks.text");' |
24
|
|
|
), |
25
|
|
|
] |
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function getNodeTypes(): array |
30
|
|
|
{ |
31
|
|
|
return [Node\Expr\FuncCall::class, Node\Expr\StaticCall::class]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function refactor(Node $node) |
35
|
|
|
{ |
36
|
|
|
$isViewCall = false; |
37
|
|
|
if ($node instanceof Node\Expr\StaticCall) { |
38
|
|
|
if ($node->name->name === 'make') { |
39
|
|
|
$isViewCall = $node->class->getLast() === 'View'; |
|
|
|
|
40
|
|
|
} |
41
|
|
|
} elseif ($node instanceof Node\Expr\FuncCall) { |
42
|
|
|
if ($node->name->parts ?? false) { |
43
|
|
|
$isViewCall = $node->name->parts[0] === 'view'; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if ($isViewCall && $node->getArgs()[0] ?? false) { |
|
|
|
|
48
|
|
|
/** @var \PhpParser\Node\Arg $arg */ |
49
|
|
|
$arg = $node->getArgs()[0]; |
50
|
|
|
if (Str::startsWith($arg->value->value, 'admin.')) { |
51
|
|
|
$node->args[0] = new Node\Arg( |
|
|
|
|
52
|
|
|
BuilderHelpers::normalizeValue(Str::replaceFirst('admin.', 'twill.', $arg->value->value)) |
53
|
|
|
); |
54
|
|
|
return $node; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return null; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.