Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
InvitationStatusType
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 getSQLDeclaration
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 convertToPHPValue
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 convertToDatabaseValue
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace App\Trip\Infrastructure\Persistence\Doctrine\Type;
6
7use App\Trip\Domain\ValueObject\InvitationStatus;
8use Doctrine\DBAL\Platforms\AbstractPlatform;
9use Doctrine\DBAL\Types\Type;
10
11final class InvitationStatusType extends Type
12{
13    public const NAME = 'invitation_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): ?InvitationStatus
23    {
24        if ($value === null) {
25            return null;
26        }
27        assert(is_string($value));
28
29        return InvitationStatus::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 InvitationStatus) {
38            return $value->value;
39        }
40        assert(is_string($value));
41
42        return $value;
43    }
44}