33namespace PHPStan \Type ;
44
55use PHPStan \Type \Accessory \AccessoryArrayListType ;
6+ use PHPStan \Type \Accessory \AccessoryLowercaseStringType ;
67use PHPStan \Type \Accessory \AccessoryNonEmptyStringType ;
78use PHPStan \Type \Accessory \AccessoryType ;
9+ use PHPStan \Type \Accessory \AccessoryUppercaseStringType ;
810use PHPStan \Type \Accessory \HasOffsetType ;
911use PHPStan \Type \Accessory \HasOffsetValueType ;
1012use PHPStan \Type \Accessory \HasPropertyType ;
@@ -452,7 +454,10 @@ private static function compareTypesInUnion(Type $a, Type $b): ?array
452454 && ($ b ->describe (VerbosityLevel::value ()) === 'non-empty-string '
453455 || $ b ->describe (VerbosityLevel::value ()) === 'non-falsy-string ' )
454456 ) {
455- return [null , new StringType ()];
457+ return [null , self ::intersect (
458+ new StringType (),
459+ ...self ::getAccessoryCaseStringTypes ($ b ),
460+ )];
456461 }
457462
458463 if (
@@ -461,34 +466,55 @@ private static function compareTypesInUnion(Type $a, Type $b): ?array
461466 && ($ a ->describe (VerbosityLevel::value ()) === 'non-empty-string '
462467 || $ a ->describe (VerbosityLevel::value ()) === 'non-falsy-string ' )
463468 ) {
464- return [new StringType (), null ];
469+ return [self ::intersect (
470+ new StringType (),
471+ ...self ::getAccessoryCaseStringTypes ($ a ),
472+ ), null ];
465473 }
466474
467475 if (
468476 $ a instanceof ConstantStringType
469477 && $ a ->getValue () === '0 '
470478 && $ b ->describe (VerbosityLevel::value ()) === 'non-falsy-string '
471479 ) {
472- return [null , new IntersectionType ([
480+ return [null , self :: intersect (
473481 new StringType (),
474482 new AccessoryNonEmptyStringType (),
475- ])];
483+ ...self ::getAccessoryCaseStringTypes ($ b ),
484+ )];
476485 }
477486
478487 if (
479488 $ b instanceof ConstantStringType
480489 && $ b ->getValue () === '0 '
481490 && $ a ->describe (VerbosityLevel::value ()) === 'non-falsy-string '
482491 ) {
483- return [new IntersectionType ([
492+ return [self :: intersect (
484493 new StringType (),
485494 new AccessoryNonEmptyStringType (),
486- ]), null ];
495+ ...self ::getAccessoryCaseStringTypes ($ a ),
496+ ), null ];
487497 }
488498
489499 return null ;
490500 }
491501
502+ /**
503+ * @return array<Type>
504+ */
505+ private static function getAccessoryCaseStringTypes (Type $ type ): array
506+ {
507+ $ accessory = [];
508+ if ($ type ->isLowercaseString ()->yes ()) {
509+ $ accessory [] = new AccessoryLowercaseStringType ();
510+ }
511+ if ($ type ->isUppercaseString ()->yes ()) {
512+ $ accessory [] = new AccessoryUppercaseStringType ();
513+ }
514+
515+ return $ accessory ;
516+ }
517+
492518 private static function unionWithSubtractedType (
493519 Type $ type ,
494520 ?Type $ subtractedType ,
0 commit comments