|
5 | 5 | use Glhd\LaraLint\Linters\Concerns\EvaluatesNodes; |
6 | 6 | use Glhd\LaraLint\Linters\Strategies\OrderingLinter; |
7 | 7 | use Illuminate\Support\Collection; |
| 8 | +use Illuminate\Support\Facades\Config; |
8 | 9 | use Illuminate\Support\Str; |
9 | 10 | use Microsoft\PhpParser\Node; |
| 11 | +use Microsoft\PhpParser\Node\ClassBaseClause; |
10 | 12 | use Microsoft\PhpParser\Node\ClassConstDeclaration; |
11 | 13 | use Microsoft\PhpParser\Node\MethodDeclaration; |
12 | 14 | use Microsoft\PhpParser\Node\PropertyDeclaration; |
13 | 15 | use Microsoft\PhpParser\Node\Statement\ClassDeclaration; |
14 | 16 | use Microsoft\PhpParser\Node\TraitUseClause; |
| 17 | +use Microsoft\PhpParser\ResolvedName; |
15 | 18 |
|
16 | 19 | class OrderClassMembers extends OrderingLinter |
17 | 20 | { |
@@ -105,6 +108,41 @@ protected function matchers() : Collection |
105 | 108 | return $this->isPrivate($node) |
106 | 109 | && false === $this->isStatic($node); |
107 | 110 | }), |
| 111 | + |
| 112 | + 'the casts method' => $this->treeMatcher() |
| 113 | + ->withChild(function(ClassDeclaration $node) { |
| 114 | + if (!$node->classBaseClause instanceof ClassBaseClause) { |
| 115 | + return false; |
| 116 | + } |
| 117 | + |
| 118 | + $resolved = $node->classBaseClause->baseClass->getResolvedName(); |
| 119 | + $extends = $resolved instanceof ResolvedName |
| 120 | + ? $resolved->getFullyQualifiedNameText() |
| 121 | + : (string) $resolved; |
| 122 | + |
| 123 | + return in_array($extends, Config::get('laralint.models', [])); |
| 124 | + }) |
| 125 | + ->withChild(function(MethodDeclaration $node) { |
| 126 | + return 'casts' === $node->getName(); |
| 127 | + }), |
| 128 | + |
| 129 | + 'the boot method' => $this->treeMatcher() |
| 130 | + ->withChild(function(ClassDeclaration $node) { |
| 131 | + if (!$node->classBaseClause instanceof ClassBaseClause) { |
| 132 | + return false; |
| 133 | + } |
| 134 | + |
| 135 | + $resolved = $node->classBaseClause->baseClass->getResolvedName(); |
| 136 | + $extends = $resolved instanceof ResolvedName |
| 137 | + ? $resolved->getFullyQualifiedNameText() |
| 138 | + : (string) $resolved; |
| 139 | + |
| 140 | + return in_array($extends, Config::get('laralint.models', [])); |
| 141 | + }) |
| 142 | + ->withChild(function(MethodDeclaration $node) { |
| 143 | + return in_array($node->getName(), ['booting', 'boot', 'booted']) |
| 144 | + && $this->isStatic($node); |
| 145 | + }), |
108 | 146 |
|
109 | 147 | 'an abstract method' => $this->treeMatcher() |
110 | 148 | ->withChild(function(MethodDeclaration $node) { |
|
0 commit comments