Skip to content

Commit fb7ef52

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

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-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+
}

0 commit comments

Comments
 (0)