88use PHPStan \Reflection \PropertiesClassReflectionExtension ;
99use PHPStan \Reflection \PropertyReflection ;
1010use PHPStan \ShouldNotHappenException ;
11+ use PHPStan \Type \NeverType ;
1112use PHPStan \Type \ObjectType ;
1213use PHPStan \Type \StringType ;
1314use PHPStan \Type \TypeCombinator ;
@@ -29,7 +30,10 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
2930 return false ;
3031 }
3132
32- $ propertyType = TypeCombinator::removeNull ($ property ->getType ()); // remove null to properly match subtype
33+ $ type = $ property ->getReadableType () ?? $ property ->getWritableType ();
34+ if ($ type === null ) throw new ShouldNotHappenException ();
35+
36+ $ propertyType = TypeCombinator::removeNull ($ type ); // remove null to properly match subtype
3337 $ dateTimeType = new ObjectType (\DateTimeImmutable::class);
3438 $ hasDateTime = $ dateTimeType ->isSuperTypeOf ($ propertyType )->yes ();
3539
@@ -40,14 +44,14 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
4044 public function getProperty (ClassReflection $ classReflection , string $ propertyName ): PropertyReflection
4145 {
4246 $ property = $ classReflection ->getPropertyTags ()[$ propertyName ] ?? null ;
43- if ($ property === null ) {
47+ if ($ property === null || $ property -> getReadableType () === null ) {
4448 throw new ShouldNotHappenException ();
4549 }
4650
4751 return new AnnotationPropertyReflection (
4852 $ classReflection ,
49- $ property ->getType (),
50- TypeCombinator::union ($ property ->getType (), new StringType ()),
53+ $ property ->getReadableType (),
54+ TypeCombinator::union ($ property ->getWritableType () ?? new NeverType (), new StringType ()),
5155 $ property ->isReadable (),
5256 $ property ->isWritable ()
5357 );
0 commit comments