Skip to content

Commit

Permalink
add symfony uuid type descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
alcohol committed Jan 21, 2025
1 parent bdb6a83 commit fb7ef52
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^9.6.20",
"ramsey/uuid": "^4.2",
"symfony/cache": "^5.4"
"symfony/cache": "^5.4",
"symfony/doctrine-bridge": "^5.4",
"symfony/validator": "^5.4",
"symfony/uid": "^5.4"
},
"config": {
"sort-packages": true,
Expand Down
3 changes: 3 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ services:
tags: [phpstan.doctrine.typeDescriptor]
arguments:
uuidTypeName: Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType
-
class: PHPStan\Type\Doctrine\Descriptors\Symfony\UuidTypeDescriptor
tags: [phpstan.doctrine.typeDescriptor]

# Doctrine Collection
-
Expand Down
35 changes: 35 additions & 0 deletions src/Type/Doctrine/Descriptors/Symfony/UuidTypeDescriptor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types = 1);

namespace PHPStan\Type\Doctrine\Descriptors\Symfony;

use PHPStan\Type\Doctrine\Descriptors\DoctrineTypeDescriptor;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;

class UuidTypeDescriptor implements DoctrineTypeDescriptor
{

public function getType(): string
{
return UuidType::class;
}

public function getWritableToPropertyType(): Type
{
return new ObjectType(Uuid::class);
}

public function getWritableToDatabaseType(): Type
{
return new ObjectType(Uuid::class);
}

public function getDatabaseInternalType(): Type
{
return new StringType();
}

}

0 comments on commit fb7ef52

Please sign in to comment.