Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit eb650bc

Browse files
committed
Ramsey UUID TypeDescriptor
1 parent 5bfde49 commit eb650bc

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

‎composer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"phpstan/phpstan-phpunit": "^0.12",
3030
"phpstan/phpstan-strict-rules": "^0.12",
3131
"phpunit/phpunit": "^7.0",
32+
"ramsey/uuid-doctrine": "^1.5.0",
3233
"slevomat/coding-standard": "^4.5.2",
3334
"doctrine/common": "^2.7",
3435
"doctrine/orm": "^2.5",

‎extension.neon‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,14 @@ services:
255255
-
256256
class: PHPStan\Type\Doctrine\Descriptors\TimeType
257257
tags: [phpstan.doctrine.typeDescriptor]
258+
259+
# 3rd party Type descriptors
260+
-
261+
class: PHPStan\Type\Doctrine\Descriptors\Ramsey\UuidTypeDescriptor
262+
tags: [phpstan.doctrine.typeDescriptor]
263+
-
264+
class: PHPStan\Type\Doctrine\Descriptors\Ramsey\UuidBinaryTypeDescriptor
265+
tags: [phpstan.doctrine.typeDescriptor]
266+
-
267+
class: PHPStan\Type\Doctrine\Descriptors\Ramsey\UuidBinaryOrderedTimeTypeDescriptor
268+
tags: [phpstan.doctrine.typeDescriptor]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Doctrine\Descriptors\Ramsey;
4+
5+
use PHPStan\Type\Doctrine\Descriptors\DoctrineTypeDescriptor;
6+
use PHPStan\Type\Type;
7+
use PHPStan\Type\TypeCombinator;
8+
use Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType;
9+
use Ramsey\Uuid\UuidInterface;
10+
11+
class UuidBinaryOrderedTimeTypeDescriptor implements DoctrineTypeDescriptor
12+
{
13+
14+
public function getType(): string
15+
{
16+
return UuidBinaryOrderedTimeType::class;
17+
}
18+
19+
public function getWritableToPropertyType(): Type
20+
{
21+
return new \PHPStan\Type\ObjectType(UuidInterface::class);
22+
}
23+
24+
public function getWritableToDatabaseType(): Type
25+
{
26+
return TypeCombinator::union(
27+
new \PHPStan\Type\StringType(),
28+
new \PHPStan\Type\ObjectType(UuidInterface::class)
29+
);
30+
}
31+
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Doctrine\Descriptors\Ramsey;
4+
5+
use PHPStan\Type\Doctrine\Descriptors\DoctrineTypeDescriptor;
6+
use PHPStan\Type\Type;
7+
use PHPStan\Type\TypeCombinator;
8+
use Ramsey\Uuid\Doctrine\UuidBinaryType;
9+
use Ramsey\Uuid\UuidInterface;
10+
11+
class UuidBinaryTypeDescriptor implements DoctrineTypeDescriptor
12+
{
13+
14+
public function getType(): string
15+
{
16+
return UuidBinaryType::class;
17+
}
18+
19+
public function getWritableToPropertyType(): Type
20+
{
21+
return new \PHPStan\Type\ObjectType(UuidInterface::class);
22+
}
23+
24+
public function getWritableToDatabaseType(): Type
25+
{
26+
return TypeCombinator::union(
27+
new \PHPStan\Type\StringType(),
28+
new \PHPStan\Type\ObjectType(UuidInterface::class)
29+
);
30+
}
31+
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Doctrine\Descriptors\Ramsey;
4+
5+
use PHPStan\Type\Doctrine\Descriptors\DoctrineTypeDescriptor;
6+
use PHPStan\Type\Type;
7+
use PHPStan\Type\TypeCombinator;
8+
use Ramsey\Uuid\Doctrine\UuidType;
9+
use Ramsey\Uuid\UuidInterface;
10+
11+
class UuidTypeDescriptor implements DoctrineTypeDescriptor
12+
{
13+
14+
public function getType(): string
15+
{
16+
return UuidType::class;
17+
}
18+
19+
public function getWritableToPropertyType(): Type
20+
{
21+
return new \PHPStan\Type\ObjectType(UuidInterface::class);
22+
}
23+
24+
public function getWritableToDatabaseType(): Type
25+
{
26+
return TypeCombinator::union(
27+
new \PHPStan\Type\StringType(),
28+
new \PHPStan\Type\ObjectType(UuidInterface::class)
29+
);
30+
}
31+
32+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /