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 (#214)
by joseph
22:21
created

LocaleIdentifierFieldTrait::setLocaleIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String;
4
5
// phpcs:disable
6
7
use Doctrine\DBAL\Types\Type;
8
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
9
use Doctrine\ORM\Mapping\Builder\FieldBuilder;
10
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\String\LocaleIdentifierFieldInterface;
11
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
12
use Symfony\Component\Validator\Constraints\Length;
13
use Symfony\Component\Validator\Constraints\Locale;
14
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
15
use Symfony\Component\Validator\Exception\InvalidOptionsException;
16
use Symfony\Component\Validator\Exception\MissingOptionsException;
17
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
18
19
// phpcs:enable
20
trait LocaleIdentifierFieldTrait
21
{
22
23
    /**
24
     * @var string|null
25
     */
26
    private $localeIdentifier;
27
28
    /**
29
     * @SuppressWarnings(PHPMD.StaticAccess)
30
     * @param ClassMetadataBuilder $builder
31
     */
32
    public static function metaForLocaleIdentifier(ClassMetadataBuilder $builder): void
33
    {
34
        $fieldBuilder = new FieldBuilder(
35
            $builder,
36
            [
37
                'fieldName' => LocaleIdentifierFieldInterface::PROP_LOCALE_IDENTIFIER,
38
                'type'      => Type::STRING,
39
                'default'   => LocaleIdentifierFieldInterface::DEFAULT_LOCALE_IDENTIFIER,
40
            ]
41
        );
42
        $fieldBuilder
43
            ->columnName(
44
                MappingHelper::getColumnNameForField(LocaleIdentifierFieldInterface::PROP_LOCALE_IDENTIFIER)
45
            )
46
            ->nullable(true)
47
            ->unique(false)
48
            ->length(50)
49
            ->build();
50
    }
51
52
    /**
53
     * This method sets the validation for this field.
54
     *
55
     * You should add in as many relevant property constraints as you see fit.
56
     *
57
     * @param ValidatorClassMetaData $metadata
58
     *
59
     * @throws MissingOptionsException
60
     * @throws InvalidOptionsException
61
     * @throws ConstraintDefinitionException
62
     */
63
    protected static function validatorMetaForPropertyLocaleIdentifier(ValidatorClassMetaData $metadata): void
64
    {
65
        $metadata->addPropertyConstraints(
66
            LocaleIdentifierFieldInterface::PROP_LOCALE_IDENTIFIER,
67
            [
68
                new Locale(['canonicalize' => true]),
69
                new Length(
70
                    [
71
                        'min' => 0,
72
                        'max' => 50,
73
                    ]
74
                )
75
            ]
76
        );
77
    }
78
79
    /**
80
     * @return string|null
81
     */
82
    public function getLocaleIdentifier(): ?string
83
    {
84
        if (null === $this->localeIdentifier) {
85
            return LocaleIdentifierFieldInterface::DEFAULT_LOCALE_IDENTIFIER;
86
        }
87
88
        return $this->localeIdentifier;
89
    }
90
91
    /**
92
     * @param string|null $localeIdentifier
93
     *
94
     * @return self
95
     */
96
    private function setLocaleIdentifier(?string $localeIdentifier): self
97
    {
98
        $this->updatePropertyValue(
0 ignored issues
show
Bug introduced by
It seems like updatePropertyValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

98
        $this->/** @scrutinizer ignore-call */ 
99
               updatePropertyValue(
Loading history...
99
            LocaleIdentifierFieldInterface::PROP_LOCALE_IDENTIFIER,
100
            $localeIdentifier
101
        );
102
103
        return $this;
104
    }
105
}
106