GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#59)
by joseph
17:21
created

metaForUnicodeLanguageIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
ccs 10
cts 10
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String;
4
5
use Doctrine\DBAL\Types\Type;
6
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
7
use Doctrine\ORM\Mapping\Builder\FieldBuilder;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\String\UnicodeLanguageIdentifierFieldInterface;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ValidatedEntityInterface;
10
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
11
use Symfony\Component\Validator\Constraints\Language;
12
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
13
14
trait UnicodeLanguageIdentifierFieldTrait
15
{
16
17
    /**
18
     * @var string|null
19
     */
20
    private $unicodeLanguageIdentifier;
21
22
    /**
23
     * @SuppressWarnings(PHPMD.StaticAccess)
24
     * @param ClassMetadataBuilder $builder
25
     */
26 1
    public static function metaForUnicodeLanguageIdentifier(ClassMetadataBuilder $builder): void
27
    {
28 1
        $fieldBuilder = new FieldBuilder(
29 1
            $builder,
30
            [
31 1
                'fieldName' => UnicodeLanguageIdentifierFieldInterface::PROP_UNICODE_LANGUAGE_IDENTIFIER,
32
                'type'      => Type::STRING,
33
                'default'   => null,
34
            ]
35
        );
36
        $fieldBuilder
37 1
            ->columnName(MappingHelper::getColumnNameForField(
38 1
                UnicodeLanguageIdentifierFieldInterface::PROP_UNICODE_LANGUAGE_IDENTIFIER
39
            ))
40 1
            ->nullable(true)
41 1
            ->unique(false)
42 1
            ->length(50)
43 1
            ->build();
44 1
    }
45
46
    /**
47
     * This method sets the validation for this field.
48
     *
49
     * You should add in as many relevant property constraints as you see fit.
50
     *
51
     * @see https://symfony.com/doc/current/validation.html#supported-constraints
52
     *
53
     * @param ValidatorClassMetaData $metadata
54
     *
55
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
56
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
57
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
58
     */
59 2
    protected static function validatorMetaForUnicodeLanguageIdentifier(ValidatorClassMetaData $metadata)
60
    {
61 2
        $metadata->addPropertyConstraint(
62 2
            UnicodeLanguageIdentifierFieldInterface::PROP_UNICODE_LANGUAGE_IDENTIFIER,
63 2
            new Language()
64
        );
65 2
    }
66
67
    /**
68
     * @return string|null
69
     */
70 2
    public function getUnicodeLanguageIdentifier(): ?string
71
    {
72 2
        if (null === $this->unicodeLanguageIdentifier) {
73 1
            return UnicodeLanguageIdentifierFieldInterface::DEFAULT_UNICODE_LANGUAGE_IDENTIFIER;
74
        }
75
76 2
        return $this->unicodeLanguageIdentifier;
77
    }
78
79
    /**
80
     * @param string|null $unicodeLanguageIdentifier
81
     *
82
     * @return self
83
     */
84 2
    public function setUnicodeLanguageIdentifier(?string $unicodeLanguageIdentifier): self
85
    {
86 2
        $this->unicodeLanguageIdentifier = $unicodeLanguageIdentifier;
87 2
        if ($this instanceof ValidatedEntityInterface) {
88 2
            $this->validateProperty(
89 2
                UnicodeLanguageIdentifierFieldInterface::PROP_UNICODE_LANGUAGE_IDENTIFIER
90
            );
91
        }
92
93 2
        return $this;
94
    }
95
}
96