Passed
Pull Request — master (#1620)
by Tarmo
63:23
created

EnumLocaleType   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 28
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A convertToPHPValue() 0 12 3
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Doctrine/DBAL/Types/EnumLocaleType.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Doctrine\DBAL\Types;
10
11
use App\Enum\Language;
0 ignored issues
show
Bug introduced by
The type App\Enum\Language was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use App\Enum\Locale;
0 ignored issues
show
Bug introduced by
The type App\Enum\Locale was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Doctrine\DBAL\Platforms\AbstractPlatform;
14
use Doctrine\DBAL\Types\ConversionException;
15
use function gettype;
16
use function implode;
17
use function is_string;
18
19
/**
20
 * Class EnumLocaleType
21
 *
22
 * @package App\Doctrine\DBAL\Types
23
 * @author TLe, Tarmo Leppänen <[email protected]>
24
 */
25
class EnumLocaleType extends EnumType
26
{
27
    protected static string $name = Types::ENUM_LOCALE;
28
29
    /**
30
     * @var class-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
31
     */
32
    protected static string $enum = Locale::class;
33
34
    /**
35
     * {@inheritdoc}
36
     *
37
     * @throws ConversionException
38
     *
39
     * @noinspection PhpMissingParentCallCommonInspection
40
     */
41
    public function convertToPHPValue($value, AbstractPlatform $platform): Locale
42
    {
43
        $enum = Locale::tryFrom($value);
44
45
        if (is_string($value) && $enum !== null) {
46
            return $enum;
47
        }
48
49
        throw ConversionException::conversionFailedFormat(
50
            gettype($value),
51
            $this->getName(),
52
            'One of: "' . implode('", "', Language::getValues()) . '"',
53
        );
54
    }
55
}
56