File tree Expand file tree Collapse file tree 4 files changed +30
-4
lines changed
Expand file tree Collapse file tree 4 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 1414use PHPStan \Reflection \TrivialParametersAcceptor ;
1515use PHPStan \TrinaryLogic ;
1616use PHPStan \Type \Constant \ConstantArrayType ;
17+ use PHPStan \Type \Constant \ConstantBooleanType ;
1718use PHPStan \Type \Constant \ConstantStringType ;
1819use PHPStan \Type \Generic \GenericObjectType ;
1920use PHPStan \Type \Traits \NonGenericTypeTrait ;
20- use PHPStan \Type \Traits \TruthyBooleanTypeTrait ;
2121use PHPStan \Type \Traits \UndecidedComparisonTypeTrait ;
2222
2323class ObjectType implements TypeWithClassName, SubtractableType
2424{
2525
26- use TruthyBooleanTypeTrait;
2726 use NonGenericTypeTrait;
2827 use UndecidedComparisonTypeTrait;
2928
@@ -396,6 +395,15 @@ public function toArray(): Type
396395 return new ConstantArrayType ($ arrayKeys , $ arrayValues );
397396 }
398397
398+ public function toBoolean (): BooleanType
399+ {
400+ if ($ this ->isInstanceOf ('SimpleXMLElement ' )->yes ()) {
401+ return new BooleanType ();
402+ }
403+
404+ return new ConstantBooleanType (true );
405+ }
406+
399407 public function canAccessProperties (): TrinaryLogic
400408 {
401409 return TrinaryLogic::createYes ();
Original file line number Diff line number Diff line change 99use PHPStan \Reflection \PropertyReflection ;
1010use PHPStan \TrinaryLogic ;
1111use PHPStan \Type \Traits \NonGenericTypeTrait ;
12- use PHPStan \Type \Traits \TruthyBooleanTypeTrait ;
1312use PHPStan \Type \Traits \UndecidedComparisonTypeTrait ;
1413
1514class StaticType implements TypeWithClassName
1615{
1716
18- use TruthyBooleanTypeTrait;
1917 use NonGenericTypeTrait;
2018 use UndecidedComparisonTypeTrait;
2119
@@ -254,6 +252,11 @@ public function toArray(): Type
254252 return $ this ->getStaticObjectType ()->toArray ();
255253 }
256254
255+ public function toBoolean (): BooleanType
256+ {
257+ return $ this ->getStaticObjectType ()->toBoolean ();
258+ }
259+
257260 public function traverse (callable $ cb ): Type
258261 {
259262 return $ this ;
Original file line number Diff line number Diff line change @@ -10419,6 +10419,11 @@ public function dataBug3760(): array
1041910419 return $ this ->gatherAssertTypes (__DIR__ . '/data/bug-3760.php ' );
1042010420 }
1042110421
10422+ public function dataBug2997 (): array
10423+ {
10424+ return $ this ->gatherAssertTypes (__DIR__ . '/data/bug-2997.php ' );
10425+ }
10426+
1042210427 /**
1042310428 * @param string $file
1042410429 * @return array<string, mixed[]>
@@ -10603,6 +10608,7 @@ private function gatherAssertTypes(string $file): array
1060310608 * @dataProvider dataIncDecInConditions
1060410609 * @dataProvider dataBug4099
1060510610 * @dataProvider dataBug3760
10611+ * @dataProvider dataBug2997
1060610612 * @param string $assertType
1060710613 * @param string $file
1060810614 * @param mixed ...$args
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug2997 ;
4+
5+ use function PHPStan \Analyser \assertType ;
6+
7+ function (\SimpleXMLElement $ xml ): void {
8+ assertType ('bool ' , (bool ) $ xml ->Exists );
9+ };
You can’t perform that action at this time.
0 commit comments