Skip to content

Commit 9ba5388

Browse files
committed
update for latest PHPStan's getType on properties
1 parent d0b92fb commit 9ba5388

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/Reflection/EntityDateTimePropertyReflectionExtension.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPStan\Reflection\PropertiesClassReflectionExtension;
99
use PHPStan\Reflection\PropertyReflection;
1010
use PHPStan\ShouldNotHappenException;
11+
use PHPStan\Type\NeverType;
1112
use PHPStan\Type\ObjectType;
1213
use PHPStan\Type\StringType;
1314
use 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
);

src/Reflection/EntityRelationshipPropertyReflectionExtension.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPStan\Reflection\PropertyReflection;
1010
use PHPStan\ShouldNotHappenException;
1111
use PHPStan\Type\IntegerType;
12+
use PHPStan\Type\NeverType;
1213
use PHPStan\Type\TypeCombinator;
1314

1415

@@ -41,14 +42,14 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
4142
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
4243
{
4344
$property = $classReflection->getPropertyTags()[$propertyName] ?? null;
44-
if ($property === null) {
45+
if ($property === null || $property->getReadableType() === null) {
4546
throw new ShouldNotHappenException();
4647
}
4748

4849
return new AnnotationPropertyReflection(
4950
$classReflection,
50-
$property->getType(),
51-
TypeCombinator::union($property->getType(), new IntegerType()),
51+
$property->getReadableType(),
52+
TypeCombinator::union($property->getWritableType() ?? new NeverType(), new IntegerType()),
5253
$property->isReadable(),
5354
$property->isWritable()
5455
);

0 commit comments

Comments
 (0)