@@ -141,15 +141,15 @@ private function shouldVarTagTypeBeReported(Node\Expr $expr, Type $type, Type $v
141
141
$ type = new ArrayType (new MixedType (), new MixedType ());
142
142
}
143
143
144
- return !$ this ->isSuperTypeOfVarType ($ type , $ varTagType, false );
144
+ return !$ this ->isAtLeastMaybeSuperTypeOfVarType ($ type , $ varTagType );
145
145
}
146
146
147
147
if ($ expr instanceof Expr \ConstFetch) {
148
- return !$ this ->isSuperTypeOfVarType ($ type , $ varTagType, false );
148
+ return !$ this ->isAtLeastMaybeSuperTypeOfVarType ($ type , $ varTagType );
149
149
}
150
150
151
151
if ($ expr instanceof Node \Scalar) {
152
- return !$ this ->isSuperTypeOfVarType ($ type , $ varTagType, false );
152
+ return !$ this ->isAtLeastMaybeSuperTypeOfVarType ($ type , $ varTagType );
153
153
}
154
154
155
155
if ($ expr instanceof Expr \New_) {
@@ -164,50 +164,58 @@ private function shouldVarTagTypeBeReported(Node\Expr $expr, Type $type, Type $v
164
164
private function checkType (Type $ type , Type $ varTagType , int $ depth = 0 ): bool
165
165
{
166
166
if ($ this ->strictWideningCheck ) {
167
- return !$ this ->isSuperTypeOfVarType ($ type , $ varTagType, true );
167
+ return !$ this ->isSuperTypeOfVarType ($ type , $ varTagType );
168
168
}
169
169
170
170
if ($ type ->isConstantArray ()->yes ()) {
171
171
if ($ type ->isIterableAtLeastOnce ()->no ()) {
172
172
$ type = new ArrayType (new MixedType (), new MixedType ());
173
- return !$ this ->isSuperTypeOfVarType ($ type , $ varTagType, false );
173
+ return !$ this ->isAtLeastMaybeSuperTypeOfVarType ($ type , $ varTagType );
174
174
}
175
175
}
176
176
177
177
if ($ type ->isIterable ()->yes () && $ varTagType ->isIterable ()->yes ()) {
178
- if (!$ this ->isSuperTypeOfVarType ($ type , $ varTagType, false )) {
178
+ if (!$ this ->isAtLeastMaybeSuperTypeOfVarType ($ type , $ varTagType )) {
179
179
return true ;
180
180
}
181
181
182
182
$ innerType = $ type ->getIterableValueType ();
183
183
$ innerVarTagType = $ varTagType ->getIterableValueType ();
184
184
185
185
if ($ type ->equals ($ innerType ) || $ varTagType ->equals ($ innerVarTagType )) {
186
- return !$ this ->isSuperTypeOfVarType ($ innerType , $ innerVarTagType, true );
186
+ return !$ this ->isSuperTypeOfVarType ($ innerType , $ innerVarTagType );
187
187
}
188
188
189
189
return $ this ->checkType ($ innerType , $ innerVarTagType , $ depth + 1 );
190
190
}
191
191
192
192
if ($ depth === 0 && $ type ->isConstantValue ()->yes ()) {
193
- return !$ this ->isSuperTypeOfVarType ($ type , $ varTagType, false );
193
+ return !$ this ->isAtLeastMaybeSuperTypeOfVarType ($ type , $ varTagType );
194
194
}
195
195
196
- return !$ this ->isSuperTypeOfVarType ($ type , $ varTagType, true );
196
+ return !$ this ->isSuperTypeOfVarType ($ type , $ varTagType );
197
197
}
198
198
199
- private function isSuperTypeOfVarType (Type $ type , Type $ varTagType, bool $ strict ): bool
199
+ private function isSuperTypeOfVarType (Type $ type , Type $ varTagType ): bool
200
200
{
201
- $ validationCallable = static fn (TrinaryLogic $ trinaryLogic ): bool => $ strict ? $ trinaryLogic ->yes () : !$ trinaryLogic ->no ();
201
+ if ($ type ->isSuperTypeOf ($ varTagType )->yes ()) {
202
+ return true ;
203
+ }
204
+
205
+ $ type = $ this ->typeNodeResolver ->resolve ($ type ->toPhpDocNode (), new NameScope (null , []));
202
206
203
- $ result = $ type ->isSuperTypeOf ($ varTagType );
204
- if ($ validationCallable ($ result )) {
207
+ return $ type ->isSuperTypeOf ($ varTagType )->yes ();
208
+ }
209
+
210
+ private function isAtLeastMaybeSuperTypeOfVarType (Type $ type , Type $ varTagType ): bool
211
+ {
212
+ if (!$ type ->isSuperTypeOf ($ varTagType )->no ()) {
205
213
return true ;
206
214
}
207
215
208
216
$ type = $ this ->typeNodeResolver ->resolve ($ type ->toPhpDocNode (), new NameScope (null , []));
209
217
210
- return $ validationCallable ( $ type ->isSuperTypeOf ($ varTagType ));
218
+ return ! $ type ->isSuperTypeOf ($ varTagType )-> no ( );
211
219
}
212
220
213
221
}
0 commit comments