Skip to content

Commit 6d4cc15

Browse files
committed
add symfony uuid type descriptor
1 parent bdb6a83 commit 6d4cc15

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
"phpstan/phpstan-strict-rules": "^2.0",
3636
"phpunit/phpunit": "^9.6.20",
3737
"ramsey/uuid": "^4.2",
38-
"symfony/cache": "^5.4"
38+
"symfony/cache": "^5.4",
39+
"symfony/doctrine-bridge": "^5.4",
40+
"symfony/validator": "^5.4",
41+
"symfony/uid": "^5.4"
3942
},
4043
"config": {
4144
"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\UuidTypeDescriptor
417+
tags: [phpstan.doctrine.typeDescriptor]
415418

416419
# Doctrine Collection
417420
-
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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\Bridge\Doctrine\Types\UuidType;
10+
use Symfony\Component\Uid\Uuid;
11+
12+
class UuidTypeDescriptor implements DoctrineTypeDescriptor
13+
{
14+
15+
public function getType(): string
16+
{
17+
return UuidType::class;
18+
}
19+
20+
public function getWritableToPropertyType(): Type
21+
{
22+
return new ObjectType(Uuid::class);
23+
}
24+
25+
public function getWritableToDatabaseType(): Type
26+
{
27+
return new ObjectType(Uuid::class);
28+
}
29+
30+
public function getDatabaseInternalType(): Type
31+
{
32+
return new StringType();
33+
}
34+
35+
}

tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ public function testRule(?string $objectManagerLoader): void
166166
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidSimpleArray type mapping mismatch: property can contain array<int> but database expects array<string>.',
167167
162,
168168
],
169+
[
170+
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$symfonyUuid type mapping mismatch: database can contain Symfony\Component\Uid\Uuid but property expects string.',
171+
174,
172+
],
169173
];
170174

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

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,10 @@ class MyBrokenEntity extends MyBrokenSuperclass
166166
* @var list<string>
167167
*/
168168
private $validSimpleArray;
169+
170+
/**
171+
* @ORM\Column(type="uuid")
172+
* @var string
173+
*/
174+
private $symfonyUuid;
169175
}

0 commit comments

Comments
 (0)