Skip to content

Commit 622eea1

Browse files
author
LDA
committed
1 parent a1a9efb commit 622eea1

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
"phpstan/phpstan-strict-rules": "^2.0",
3737
"phpunit/phpunit": "^9.6.20",
3838
"ramsey/uuid": "^4.2",
39-
"symfony/cache": "^5.4"
39+
"symfony/cache": "^6.4",
40+
"symfony/clock": "^6.4",
41+
"symfony/doctrine-bridge": "^7.3",
42+
"symfony/validator": "^6.4"
4043
},
4144
"config": {
4245
"sort-packages": true,

extension.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ services:
412412
tags: [phpstan.doctrine.typeDescriptor]
413413
arguments:
414414
uuidTypeName: Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType
415+
-
416+
class: PHPStan\Type\Doctrine\Descriptors\Symfony\DatePointType
417+
tags: [phpstan.doctrine.typeDescriptor]
415418

416419
# Doctrine Collection
417420
-
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Doctrine\Descriptors\Symfony;
4+
5+
use PHPStan\Type\Doctrine\Descriptors\DoctrineTypeDescriptor;
6+
use PHPStan\Type\ObjectType;
7+
use PHPStan\Type\StringType;
8+
use PHPStan\Type\Type;
9+
use Symfony\Component\Clock\DatePoint;
10+
11+
class DatePointType implements DoctrineTypeDescriptor
12+
{
13+
14+
public function getType(): string
15+
{
16+
return \Symfony\Bridge\Doctrine\Types\DatePointType::class;
17+
}
18+
19+
public function getWritableToPropertyType(): Type
20+
{
21+
return new ObjectType(DatePoint::class);
22+
}
23+
24+
public function getWritableToDatabaseType(): Type
25+
{
26+
return new ObjectType(DatePoint::class);
27+
}
28+
29+
public function getDatabaseInternalType(): Type
30+
{
31+
return new StringType();
32+
}
33+
34+
}

tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
use PHPStan\Type\Doctrine\Descriptors\ReflectionDescriptor;
2525
use PHPStan\Type\Doctrine\Descriptors\SimpleArrayType;
2626
use PHPStan\Type\Doctrine\Descriptors\StringType;
27+
use PHPStan\Type\Doctrine\Descriptors\Symfony\DatePointType;
2728
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
29+
use Symfony\Component\Clock\DatePoint;
2830
use function array_unshift;
2931
use function strpos;
3032
use const PHP_VERSION_ID;
@@ -59,6 +61,9 @@ protected function getRule(): Rule
5961
if (!Type::hasType('array')) {
6062
Type::addType('array', \Doctrine\DBAL\Types\ArrayType::class);
6163
}
64+
if (!Type::hasType('date_point')) {
65+
Type::addType('date_point', \Symfony\Bridge\Doctrine\Types\DatePointType::class);
66+
}
6267

6368
return new EntityColumnRule(
6469
new ObjectMetadataResolver($this->objectManagerLoader, __DIR__ . '/../../../../tmp'),
@@ -79,6 +84,7 @@ protected function getRule(): Rule
7984
new ReflectionDescriptor(CarbonType::class, $this->createReflectionProvider(), self::getContainer()),
8085
new ReflectionDescriptor(CustomType::class, $this->createReflectionProvider(), self::getContainer()),
8186
new ReflectionDescriptor(CustomNumericType::class, $this->createReflectionProvider(), self::getContainer()),
87+
new DatePointType(),
8288
]),
8389
$this->createReflectionProvider(),
8490
true,
@@ -166,6 +172,14 @@ public function testRule(?string $objectManagerLoader): void
166172
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidSimpleArray type mapping mismatch: property can contain array<int> but database expects array<string>.',
167173
162,
168174
],
175+
[
176+
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: database can contain Symfony\Component\Clock\DatePoint but property expects DateTime.',
177+
175,
178+
],
179+
[
180+
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: property can contain DateTime but database expects Symfony\Component\Clock\DatePoint.',
181+
175,
182+
],
169183
];
170184

171185
$dbalVersion = InstalledVersions::getVersion('doctrine/dbal');
@@ -237,6 +251,14 @@ public function testRuleWithAllowedNullableProperty(?string $objectManagerLoader
237251
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidSimpleArray type mapping mismatch: property can contain array<int> but database expects array<string>.',
238252
162,
239253
],
254+
[
255+
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: database can contain Symfony\Component\Clock\DatePoint but property expects DateTime.',
256+
175,
257+
],
258+
[
259+
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: property can contain DateTime but database expects Symfony\Component\Clock\DatePoint.',
260+
175,
261+
],
240262
];
241263

242264
$dbalVersion = InstalledVersions::getVersion('doctrine/dbal');

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,18 @@ class MyBrokenEntity extends MyBrokenSuperclass
166166
* @var list<string>
167167
*/
168168
private $validSimpleArray;
169+
170+
171+
/**
172+
* @ORM\Column(type="date_point")
173+
* @var \DateTime
174+
*/
175+
private $invalidDatePoint;
176+
177+
/**
178+
* @ORM\Column(type="date_point")
179+
* @var \Symfony\Component\Clock\DatePoint
180+
*/
181+
private $validDatePoint;
182+
169183
}

0 commit comments

Comments
 (0)