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
Push — master ( a48bd8...83d092 )
by joseph
16:18 queued 18s
created

CountryCodeFieldTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 75
ccs 0
cts 38
cp 0
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

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

82
        $this->/** @scrutinizer ignore-call */ 
83
               updatePropertyValue(
Loading history...
83
            CountryCodeFieldInterface::PROP_COUNTRY_CODE,
84
            $countryCode
85
        );
86
87
        return $this;
88
    }
89
}
90