You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 575f038
Browse filesBrowse the repository at this point in the historyBrowse files
@phpstan-type Foo<T> declares parameters that Foo<int> replaces. A bare
alias, a wrong number of arguments and an argument outside its bound make
the type unresolvable. An alias that refers to itself becomes a recursive
type when its arguments repeat, and is invalid when they grow. A parameter
named like a template of the class is reported as typeAlias.shadowTemplate.
A global alias declares its parameters in its key in the typeAliases
parameter, like 'Foo<T of int>': 'list<T>', and resolves like a local one.
Amp-Thread-ID: https://ampcode.com/threads/T-01a22307-fb39-7133-a55b-a5cc3cda81e7
Copy file name to clipboardExpand all lines: src/Rules/Classes/LocalTypeAliasesCheck.php
+37-3Lines changed: 37 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -27,9 +27,13 @@
27
27
usePHPStan\Type\TypeTraverser;
28
28
usePHPStan\Type\VerbosityLevel;
29
29
usefunctionarray_key_exists;
30
+
usefunctionarray_keys;
30
31
usefunctionarray_merge;
32
+
usefunctionexplode;
31
33
usefunctionin_array;
32
34
usefunctionsprintf;
35
+
usefunctionstrtolower;
36
+
usefunctiontrim;
33
37
34
38
#[AutowiredService]
35
39
finalclass LocalTypeAliasesCheck
@@ -138,7 +142,7 @@ public function checkInTraitDefinitionContext(ClassReflection $reflection): arra
138
142
continue;
139
143
}
140
144
141
-
if (array_key_exists($aliasName, $this->globalTypeAliases)) {
145
+
if ($this->isGlobalTypeAlias($aliasName)) {
142
146
$errors[] = RuleErrorBuilder::message(sprintf('Type alias %s already exists as a global type alias.', $aliasName))->identifier('typeAlias.duplicate')->build();
143
147
continue;
144
148
}
@@ -203,7 +207,7 @@ public function checkInTraitDefinitionContext(ClassReflection $reflection): arra
203
207
continue;
204
208
}
205
209
206
-
if (array_key_exists($aliasName, $this->globalTypeAliases)) {
210
+
if ($this->isGlobalTypeAlias($aliasName)) {
207
211
$errors[] = RuleErrorBuilder::message(sprintf('Type alias %s already exists as a global type alias.', $aliasName))->identifier('typeAlias.duplicate')->build();
208
212
continue;
209
213
}
@@ -215,7 +219,25 @@ public function checkInTraitDefinitionContext(ClassReflection $reflection): arra
0 commit comments