Skip to content

Commit 5bfde49

Browse files
committed
Do not complain about properties with missing and broken types
1 parent 2f46669 commit 5bfde49

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

src/Rules/Doctrine/ORM/EntityColumnRule.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use PHPStan\Type\Doctrine\DescriptorNotRegisteredException;
1010
use PHPStan\Type\Doctrine\DescriptorRegistry;
1111
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
12+
use PHPStan\Type\ErrorType;
13+
use PHPStan\Type\MixedType;
14+
use PHPStan\Type\NeverType;
1215
use PHPStan\Type\TypeCombinator;
1316
use PHPStan\Type\VerbosityLevel;
1417
use Throwable;
@@ -112,7 +115,12 @@ public function processNode(Node $node, Scope $scope): array
112115
$writableToDatabaseType = TypeCombinator::addNull($writableToDatabaseType);
113116
}
114117

115-
if (!$property->getWritableType()->isSuperTypeOf($writableToPropertyType)->yes()) {
118+
$propertyWritableType = $property->getWritableType();
119+
if (get_class($propertyWritableType) === MixedType::class || $propertyWritableType instanceof ErrorType || $propertyWritableType instanceof NeverType) {
120+
return [];
121+
}
122+
123+
if (!$propertyWritableType->isSuperTypeOf($writableToPropertyType)->yes()) {
116124
$errors[] = sprintf(
117125
'Property %s::$%s type mapping mismatch: database can contain %s but property expects %s.',
118126
$className,

src/Rules/Doctrine/ORM/EntityRelationRule.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
use PHPStan\Reflection\MissingPropertyFromReflectionException;
88
use PHPStan\Rules\Rule;
99
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
10+
use PHPStan\Type\ErrorType;
1011
use PHPStan\Type\IterableType;
1112
use PHPStan\Type\MixedType;
13+
use PHPStan\Type\NeverType;
1214
use PHPStan\Type\ObjectType;
1315
use PHPStan\Type\TypeCombinator;
1416
use PHPStan\Type\VerbosityLevel;
@@ -97,7 +99,11 @@ public function processNode(Node $node, Scope $scope): array
9799

98100
$errors = [];
99101
if ($columnType !== null) {
100-
if (!$property->getWritableType()->isSuperTypeOf($columnType)->yes()) {
102+
$propertyWritableType = $property->getWritableType();
103+
if (get_class($propertyWritableType) === MixedType::class || $propertyWritableType instanceof ErrorType || $propertyWritableType instanceof NeverType) {
104+
return [];
105+
}
106+
if (!$propertyWritableType->isSuperTypeOf($columnType)->yes()) {
101107
$errors[] = sprintf(
102108
'Property %s::$%s type mapping mismatch: database can contain %s but property expects %s.',
103109
$className,

tests/Rules/Doctrine/ORM/data/EntityWithRelations.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,15 @@ class EntityWithRelations
4141
*/
4242
private $manyToMany;
4343

44+
/**
45+
* @ORM\ManyToOne(targetEntity="PHPStan\Rules\Doctrine\ORM\AnotherEntity")
46+
*/
47+
private $mixed;
48+
49+
/**
50+
* @ORM\ManyToOne(targetEntity="PHPStan\Rules\Doctrine\ORM\AnotherEntity")
51+
* @var int&string
52+
*/
53+
private $never;
54+
4455
}

tests/Rules/Doctrine/ORM/data/MyBrokenEntity.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,15 @@ class MyBrokenEntity extends MyBrokenSuperclass
4848
*/
4949
private $six;
5050

51+
/**
52+
* @ORM\Column(type="date")
53+
*/
54+
private $mixed;
55+
56+
/**
57+
* @ORM\Column(type="date")
58+
* @var int&string
59+
*/
60+
private $never;
61+
5162
}

0 commit comments

Comments
 (0)