1010use PHPStan \PhpDocParser \Ast \Type \ObjectShapeNode ;
1111use PHPStan \PhpDocParser \Ast \Type \TypeNode ;
1212use PHPStan \Reflection \ClassMemberAccessAnswerer ;
13+ use PHPStan \Reflection \Dummy \DummyPropertyReflection ;
1314use PHPStan \Reflection \ExtendedPropertyReflection ;
1415use PHPStan \Reflection \MissingPropertyFromReflectionException ;
1516use PHPStan \Reflection \Php \UniversalObjectCratesClassReflectionExtension ;
@@ -113,15 +114,14 @@ public function getUnresolvedPropertyPrototype(string $propertyName, ClassMember
113114
114115 public function hasInstanceProperty (string $ propertyName ): TrinaryLogic
115116 {
116- if (!array_key_exists ($ propertyName , $ this ->properties )) {
117- return TrinaryLogic::createNo ();
117+ if (
118+ array_key_exists ($ propertyName , $ this ->properties )
119+ && !in_array ($ propertyName , $ this ->optionalProperties , true )
120+ ) {
121+ return TrinaryLogic::createYes ();
118122 }
119123
120- if (in_array ($ propertyName , $ this ->optionalProperties , true )) {
121- return TrinaryLogic::createMaybe ();
122- }
123-
124- return TrinaryLogic::createYes ();
124+ return TrinaryLogic::createMaybe ();
125125 }
126126
127127 public function getInstanceProperty (string $ propertyName , ClassMemberAccessAnswerer $ scope ): ExtendedPropertyReflection
@@ -131,11 +131,12 @@ public function getInstanceProperty(string $propertyName, ClassMemberAccessAnswe
131131
132132 public function getUnresolvedInstancePropertyPrototype (string $ propertyName , ClassMemberAccessAnswerer $ scope ): UnresolvedPropertyPrototypeReflection
133133 {
134- if (!array_key_exists ($ propertyName , $ this ->properties )) {
135- throw new ShouldNotHappenException ();
134+ if (array_key_exists ($ propertyName , $ this ->properties )) {
135+ $ property = new ObjectShapePropertyReflection ($ propertyName , $ this ->properties [$ propertyName ]);
136+ } else {
137+ $ property = new DummyPropertyReflection ($ propertyName );
136138 }
137139
138- $ property = new ObjectShapePropertyReflection ($ propertyName , $ this ->properties [$ propertyName ]);
139140 return new CallbackUnresolvedPropertyPrototypeReflection (
140141 $ property ,
141142 $ property ->getDeclaringClass (),
@@ -297,10 +298,6 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
297298 foreach ($ this ->properties as $ propertyName => $ propertyType ) {
298299 $ hasProperty = new IsSuperTypeOfResult ($ type ->hasInstanceProperty ((string ) $ propertyName ), []);
299300 if ($ hasProperty ->no ()) {
300- if ($ type instanceof self) {
301- $ result = $ result ->and (IsSuperTypeOfResult::createMaybe ());
302- continue ;
303- }
304301 if (in_array ($ propertyName , $ this ->optionalProperties , true )) {
305302 continue ;
306303 }
0 commit comments