|
2 | 2 |
|
3 | 3 | namespace PHPStan\Rules\Doctrine\ORM;
|
4 | 4 |
|
| 5 | +use Carbon\Doctrine\CarbonImmutableType; |
| 6 | +use Carbon\Doctrine\CarbonType; |
5 | 7 | use Doctrine\DBAL\Types\Type;
|
6 | 8 | use Iterator;
|
7 | 9 | use PHPStan\Rules\Rule;
|
@@ -38,22 +40,30 @@ protected function getRule(): Rule
|
38 | 40 | if (!Type::hasType(UuidType::NAME)) {
|
39 | 41 | Type::addType(UuidType::NAME, UuidType::class);
|
40 | 42 | }
|
| 43 | + if (!Type::hasType('carbon')) { |
| 44 | + Type::addType('carbon', \Carbon\Doctrine\CarbonType::class); |
| 45 | + } |
| 46 | + if (!Type::hasType('carbon_immutable')) { |
| 47 | + Type::addType('carbon_immutable', \Carbon\Doctrine\CarbonImmutableType::class); |
| 48 | + } |
41 | 49 |
|
42 | 50 | return new EntityColumnRule(
|
43 | 51 | new ObjectMetadataResolver($this->createReflectionProvider(), __DIR__ . '/entity-manager.php', null),
|
44 | 52 | new DescriptorRegistry([
|
| 53 | + new ArrayType(), |
45 | 54 | new BigIntType(),
|
46 |
| - new StringType(), |
47 |
| - new DateTimeType(), |
48 |
| - new DateTimeImmutableType(), |
49 | 55 | new BinaryType(),
|
| 56 | + new DateTimeImmutableType(), |
| 57 | + new DateTimeType(), |
| 58 | + new DateType(), |
| 59 | + new DecimalType(), |
50 | 60 | new IntegerType(),
|
| 61 | + new StringType(), |
| 62 | + new UuidTypeDescriptor(UuidType::class), |
| 63 | + new ReflectionDescriptor(CarbonImmutableType::class, $this->createBroker()), |
| 64 | + new ReflectionDescriptor(CarbonType::class, $this->createBroker()), |
51 | 65 | new ReflectionDescriptor(CustomType::class, $this->createBroker()),
|
52 | 66 | new ReflectionDescriptor(CustomNumericType::class, $this->createBroker()),
|
53 |
| - new DateType(), |
54 |
| - new UuidTypeDescriptor(UuidType::class), |
55 |
| - new ArrayType(), |
56 |
| - new DecimalType(), |
57 | 67 | ]),
|
58 | 68 | true
|
59 | 69 | );
|
@@ -106,6 +116,14 @@ public function testRule(): void
|
106 | 116 | 'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$numericString type mapping mismatch: database can contain string but property expects string&numeric.',
|
107 | 117 | 126,
|
108 | 118 | ],
|
| 119 | + [ |
| 120 | + 'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidCarbon type mapping mismatch: database can contain Carbon\Carbon but property expects Carbon\CarbonImmutable.', |
| 121 | + 132, |
| 122 | + ], |
| 123 | + [ |
| 124 | + 'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidCarbonImmutable type mapping mismatch: database can contain Carbon\CarbonImmutable but property expects Carbon\Carbon.', |
| 125 | + 138, |
| 126 | + ], |
109 | 127 | ]);
|
110 | 128 | }
|
111 | 129 |
|
|
0 commit comments