@@ -538,6 +538,72 @@ public function getUnresolvedPropertyPrototype(string $propertyName, ClassMember
538
538
return new IntersectionTypeUnresolvedPropertyPrototypeReflection ($ propertyName , $ propertyPrototypes );
539
539
}
540
540
541
+ public function hasInstanceProperty (string $ propertyName ): TrinaryLogic
542
+ {
543
+ return $ this ->intersectResults (static fn (Type $ type ): TrinaryLogic => $ type ->hasInstanceProperty ($ propertyName ));
544
+ }
545
+
546
+ public function getInstanceProperty (string $ propertyName , ClassMemberAccessAnswerer $ scope ): ExtendedPropertyReflection
547
+ {
548
+ return $ this ->getUnresolvedInstancePropertyPrototype ($ propertyName , $ scope )->getTransformedProperty ();
549
+ }
550
+
551
+ public function getUnresolvedInstancePropertyPrototype (string $ propertyName , ClassMemberAccessAnswerer $ scope ): UnresolvedPropertyPrototypeReflection
552
+ {
553
+ $ propertyPrototypes = [];
554
+ foreach ($ this ->types as $ type ) {
555
+ if (!$ type ->hasProperty ($ propertyName )->yes ()) {
556
+ continue ;
557
+ }
558
+
559
+ $ propertyPrototypes [] = $ type ->getUnresolvedInstancePropertyPrototype ($ propertyName , $ scope )->withFechedOnType ($ this );
560
+ }
561
+
562
+ $ propertiesCount = count ($ propertyPrototypes );
563
+ if ($ propertiesCount === 0 ) {
564
+ throw new ShouldNotHappenException ();
565
+ }
566
+
567
+ if ($ propertiesCount === 1 ) {
568
+ return $ propertyPrototypes [0 ];
569
+ }
570
+
571
+ return new IntersectionTypeUnresolvedPropertyPrototypeReflection ($ propertyName , $ propertyPrototypes );
572
+ }
573
+
574
+ public function hasStaticProperty (string $ propertyName ): TrinaryLogic
575
+ {
576
+ return $ this ->intersectResults (static fn (Type $ type ): TrinaryLogic => $ type ->hasStaticProperty ($ propertyName ));
577
+ }
578
+
579
+ public function getStaticProperty (string $ propertyName , ClassMemberAccessAnswerer $ scope ): ExtendedPropertyReflection
580
+ {
581
+ return $ this ->getUnresolvedStaticPropertyPrototype ($ propertyName , $ scope )->getTransformedProperty ();
582
+ }
583
+
584
+ public function getUnresolvedStaticPropertyPrototype (string $ propertyName , ClassMemberAccessAnswerer $ scope ): UnresolvedPropertyPrototypeReflection
585
+ {
586
+ $ propertyPrototypes = [];
587
+ foreach ($ this ->types as $ type ) {
588
+ if (!$ type ->hasStaticProperty ($ propertyName )->yes ()) {
589
+ continue ;
590
+ }
591
+
592
+ $ propertyPrototypes [] = $ type ->getUnresolvedStaticPropertyPrototype ($ propertyName , $ scope )->withFechedOnType ($ this );
593
+ }
594
+
595
+ $ propertiesCount = count ($ propertyPrototypes );
596
+ if ($ propertiesCount === 0 ) {
597
+ throw new ShouldNotHappenException ();
598
+ }
599
+
600
+ if ($ propertiesCount === 1 ) {
601
+ return $ propertyPrototypes [0 ];
602
+ }
603
+
604
+ return new IntersectionTypeUnresolvedPropertyPrototypeReflection ($ propertyName , $ propertyPrototypes );
605
+ }
606
+
541
607
public function canCallMethods (): TrinaryLogic
542
608
{
543
609
return $ this ->intersectResults (static fn (Type $ type ): TrinaryLogic => $ type ->canCallMethods ());
0 commit comments