2
2
3
3
namespace PHPStan \Rules \Classes ;
4
4
5
+ use PhpParser \Node \Stmt \ClassLike ;
5
6
use PHPStan \Analyser \NameScope ;
6
7
use PHPStan \PhpDoc \TypeNodeResolver ;
7
8
use PHPStan \PhpDocParser \Ast \Type \IdentifierTypeNode ;
8
9
use PHPStan \Reflection \ClassReflection ;
9
10
use PHPStan \Reflection \ReflectionProvider ;
11
+ use PHPStan \Rules \ClassNameCheck ;
12
+ use PHPStan \Rules \ClassNameNodePair ;
10
13
use PHPStan \Rules \IdentifierRuleError ;
11
14
use PHPStan \Rules \MissingTypehintCheck ;
12
15
use PHPStan \Rules \RuleErrorBuilder ;
@@ -31,7 +34,9 @@ public function __construct(
31
34
private ReflectionProvider $ reflectionProvider ,
32
35
private TypeNodeResolver $ typeNodeResolver ,
33
36
private MissingTypehintCheck $ missingTypehintCheck ,
37
+ private ClassNameCheck $ classCheck ,
34
38
private bool $ checkMissingTypehints ,
39
+ private bool $ checkClassCaseSensitivity ,
35
40
private bool $ absentTypeChecks ,
36
41
)
37
42
{
@@ -40,7 +45,7 @@ public function __construct(
40
45
/**
41
46
* @return list<IdentifierRuleError>
42
47
*/
43
- public function check (ClassReflection $ reflection ): array
48
+ public function check (ClassReflection $ reflection, ClassLike $ node ): array
44
49
{
45
50
$ phpDoc = $ reflection ->getResolvedPhpDoc ();
46
51
if ($ phpDoc === null ) {
@@ -214,6 +219,26 @@ public function check(ClassReflection $reflection): array
214
219
))->identifier ('missingType.callable ' )->build ();
215
220
}
216
221
}
222
+
223
+ foreach ($ resolvedType ->getReferencedClasses () as $ class ) {
224
+ if (!$ this ->reflectionProvider ->hasClass ($ class )) {
225
+ $ errors [] = RuleErrorBuilder::message (sprintf ('Type alias %s contains unknown class %s. ' , $ aliasName , $ class ))
226
+ ->identifier ('class.notFound ' )
227
+ ->discoveringSymbolsTip ()
228
+ ->build ();
229
+ } elseif ($ this ->reflectionProvider ->getClass ($ class )->isTrait ()) {
230
+ $ errors [] = RuleErrorBuilder::message (sprintf ('Type alias %s contains invalid type %s. ' , $ aliasName , $ class ))
231
+ ->identifier ('typeAlias.trait ' )
232
+ ->build ();
233
+ } else {
234
+ $ errors = array_merge (
235
+ $ errors ,
236
+ $ this ->classCheck ->checkClassNames ([
237
+ new ClassNameNodePair ($ class , $ node ),
238
+ ], $ this ->checkClassCaseSensitivity ),
239
+ );
240
+ }
241
+ }
217
242
}
218
243
}
219
244
0 commit comments