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

EnumLanguageType   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/EnumLanguageType.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 Doctrine\DBAL\Platforms\AbstractPlatform;
13
use Doctrine\DBAL\Types\ConversionException;
14
use function gettype;
15
use function implode;
16
use function is_string;
17
18
/**
19
 * Class EnumLanguageType
20
 *
21
 * @package App\Doctrine\DBAL\Types
22
 * @author TLe, Tarmo Leppänen <[email protected]>
23
 */
24
class EnumLanguageType extends EnumType
25
{
26
    protected static string $name = Types::ENUM_LANGUAGE;
27
28
    /**
29
     * @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...
30
     */
31
    protected static string $enum = Language::class;
32
33
    /**
34
     * {@inheritdoc}
35
     *
36
     * @throws ConversionException
37
     *
38
     * @noinspection PhpMissingParentCallCommonInspection
39
     */
40
    public function convertToPHPValue($value, AbstractPlatform $platform): Language
41
    {
42
        $enum = Language::tryFrom($value);
43
44
        if (is_string($value) && $enum !== null) {
45
            return $enum;
46
        }
47
48
        throw ConversionException::conversionFailedFormat(
49
            gettype($value),
50
            $this->getName(),
51
            'One of: "' . implode('", "', Language::getValues()) . '"',
52
        );
53
    }
54
}
55