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
19:28
created

CountryCodeFieldTrait::metaForCountryCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
ccs 9
cts 9
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\CountryCodeFieldInterface;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ValidatedEntityInterface;
10
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
11
use Symfony\Component\Validator\Constraints\Country;
12
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
13
14
trait CountryCodeFieldTrait
15
{
16
17
    /**
18
     * @var string|null
19
     */
20
    private $countryCode;
21
22
    /**
23
     * @SuppressWarnings(PHPMD.StaticAccess)
24
     */
25 1
    public static function metaForCountryCode(ClassMetadataBuilder $builder)
26
    {
27 1
        $fieldBuilder = new FieldBuilder(
28 1
            $builder,
29
            [
30 1
                'fieldName' => CountryCodeFieldInterface::PROP_COUNTRY_CODE,
31
                'type'      => Type::STRING,
32
                'default'   => CountryCodeFieldInterface::DEFAULT_COUNTRY_CODE,
33
            ]
34
        );
35
        $fieldBuilder
36 1
            ->columnName(MappingHelper::getColumnNameForField(CountryCodeFieldInterface::PROP_COUNTRY_CODE))
37 1
            ->nullable(CountryCodeFieldInterface::DEFAULT_COUNTRY_CODE === null)
38 1
            ->unique(false)
39 1
            ->length(6)
40 1
            ->build();
41 1
    }
42
43
    /**
44
     * This method sets the validation for this field.
45
     *
46
     * You should add in as many relevant property constraints as you see fit.
47
     *
48
     * @see https://symfony.com/doc/current/validation.html#supported-constraints
49
     *
50
     * @param ValidatorClassMetaData $metadata
51
     *
52
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
53
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
54
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
55
     */
56 2
    protected static function validatorMetaForCountryCode(ValidatorClassMetaData $metadata)
57
    {
58 2
        $metadata->addPropertyConstraint(
59 2
            CountryCodeFieldInterface::PROP_COUNTRY_CODE,
60 2
            new Country()
61
        );
62 2
    }
63
64
    /**
65
     * @return string|null
66
     */
67 2
    public function getCountryCode(): ?string
68
    {
69 2
        if (null === $this->countryCode) {
70 1
            return CountryCodeFieldInterface::DEFAULT_COUNTRY_CODE;
71
        }
72
73 2
        return $this->countryCode;
74
    }
75
76
    /**
77
     * @param string|null $countryCode
78
     *
79
     * @return self
80
     */
81 2
    public function setCountryCode(?string $countryCode): self
82
    {
83 2
        $this->countryCode = $countryCode;
84 2
        if ($this instanceof ValidatedEntityInterface) {
85 2
            $this->validateProperty(CountryCodeFieldInterface::PROP_COUNTRY_CODE);
86
        }
87
88 2
        return $this;
89
    }
90
}
91