Skip to content

Commit 56412dd

Browse files
phpstan-botclaude
andcommitted
Override string/scalar type queries on HasMethodType/HasPropertyType to return Maybe
HasMethodType and HasPropertyType use ObjectTypeTrait which returns No for isString(), isClassString(), isLiteralString(), etc. But these accessory types are agnostic about whether the underlying type is an object or a class-string — method_exists() and property_exists() work on both. Returning No breaks CompoundType delegation: when AccessoryLiteralStringType::isSubTypeOf(HasMethodType) checks HasMethodType::isLiteralString(), it gets No and incorrectly concludes the types are incompatible. Override the 9 string/scalar methods to return Maybe, keeping ObjectTypeTrait for object-related behavior (isObject, canCallMethods, etc.). This fixes the CompoundType delegation and removes the need for the ImpossibleCheckTypeHelper workaround. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5732696 commit 56412dd

3 files changed

Lines changed: 90 additions & 3 deletions

File tree

src/Rules/Comparison/ImpossibleCheckTypeHelper.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,7 @@ public function findSpecifiedType(
241241
&& $genericType->hasMethod($methodType->getValue())->no()) {
242242
return false;
243243
}
244-
245-
return null;
246244
}
247-
248245
}
249246
}
250247
}

src/Type/Accessory/HasMethodType.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,51 @@ public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope)
181181
];
182182
}
183183

184+
public function isString(): TrinaryLogic
185+
{
186+
return TrinaryLogic::createMaybe();
187+
}
188+
189+
public function isNumericString(): TrinaryLogic
190+
{
191+
return TrinaryLogic::createMaybe();
192+
}
193+
194+
public function isNonEmptyString(): TrinaryLogic
195+
{
196+
return TrinaryLogic::createMaybe();
197+
}
198+
199+
public function isNonFalsyString(): TrinaryLogic
200+
{
201+
return TrinaryLogic::createMaybe();
202+
}
203+
204+
public function isLiteralString(): TrinaryLogic
205+
{
206+
return TrinaryLogic::createMaybe();
207+
}
208+
209+
public function isLowercaseString(): TrinaryLogic
210+
{
211+
return TrinaryLogic::createMaybe();
212+
}
213+
214+
public function isUppercaseString(): TrinaryLogic
215+
{
216+
return TrinaryLogic::createMaybe();
217+
}
218+
219+
public function isClassString(): TrinaryLogic
220+
{
221+
return TrinaryLogic::createMaybe();
222+
}
223+
224+
public function isScalar(): TrinaryLogic
225+
{
226+
return TrinaryLogic::createMaybe();
227+
}
228+
184229
public function getEnumCases(): array
185230
{
186231
return [];

src/Type/Accessory/HasPropertyType.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,51 @@ public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope)
158158
return [new TrivialParametersAcceptor()];
159159
}
160160

161+
public function isString(): TrinaryLogic
162+
{
163+
return TrinaryLogic::createMaybe();
164+
}
165+
166+
public function isNumericString(): TrinaryLogic
167+
{
168+
return TrinaryLogic::createMaybe();
169+
}
170+
171+
public function isNonEmptyString(): TrinaryLogic
172+
{
173+
return TrinaryLogic::createMaybe();
174+
}
175+
176+
public function isNonFalsyString(): TrinaryLogic
177+
{
178+
return TrinaryLogic::createMaybe();
179+
}
180+
181+
public function isLiteralString(): TrinaryLogic
182+
{
183+
return TrinaryLogic::createMaybe();
184+
}
185+
186+
public function isLowercaseString(): TrinaryLogic
187+
{
188+
return TrinaryLogic::createMaybe();
189+
}
190+
191+
public function isUppercaseString(): TrinaryLogic
192+
{
193+
return TrinaryLogic::createMaybe();
194+
}
195+
196+
public function isClassString(): TrinaryLogic
197+
{
198+
return TrinaryLogic::createMaybe();
199+
}
200+
201+
public function isScalar(): TrinaryLogic
202+
{
203+
return TrinaryLogic::createMaybe();
204+
}
205+
161206
public function getEnumCases(): array
162207
{
163208
return [];

0 commit comments

Comments
 (0)