Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
6 / 12 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| UserStatusType | |
50.00% |
6 / 12 |
|
0.00% |
0 / 3 |
10.50 | |
0.00% |
0 / 1 |
| getSQLDeclaration | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| convertToPHPValue | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| convertToDatabaseValue | |
50.00% |
3 / 6 |
|
0.00% |
0 / 1 |
4.12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Identity\Infrastructure\Persistence\Doctrine\Type; |
| 6 | |
| 7 | use App\Identity\Domain\ValueObject\UserStatus; |
| 8 | use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 9 | use Doctrine\DBAL\Types\Type; |
| 10 | |
| 11 | final class UserStatusType extends Type |
| 12 | { |
| 13 | public const NAME = 'user_status'; |
| 14 | |
| 15 | public function getSQLDeclaration(array $column, AbstractPlatform $platform): string |
| 16 | { |
| 17 | $column['length'] = 20; |
| 18 | |
| 19 | return $platform->getStringTypeDeclarationSQL($column); |
| 20 | } |
| 21 | |
| 22 | public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?UserStatus |
| 23 | { |
| 24 | if ($value === null) { |
| 25 | return null; |
| 26 | } |
| 27 | assert(is_string($value)); |
| 28 | |
| 29 | return UserStatus::from($value); |
| 30 | } |
| 31 | |
| 32 | public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string |
| 33 | { |
| 34 | if ($value === null) { |
| 35 | return null; |
| 36 | } |
| 37 | if ($value instanceof UserStatus) { |
| 38 | return $value->value; |
| 39 | } |
| 40 | assert(is_string($value)); |
| 41 | |
| 42 | return $value; |
| 43 | } |
| 44 | } |