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 (#152)
by joseph
17:58
created

IpAddressFieldTrait::setIpAddress()   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\IpAddressFieldInterface;
11
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
12
use Symfony\Component\Validator\Constraints\Ip;
13
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
14
15
// phpcs:enable
16
trait IpAddressFieldTrait
17
{
18
19
    /**
20
     * @var string|null
21
     */
22
    private $ipAddress;
23
24
    /**
25
     * @SuppressWarnings(PHPMD.StaticAccess)
26
     * @param ClassMetadataBuilder $builder
27
     *
28
     * @see https://stackoverflow.com/a/1076755/543455
29
     */
30
    public static function metaForIpAddress(ClassMetadataBuilder $builder): void
31
    {
32
        $fieldBuilder = new FieldBuilder(
33
            $builder,
34
            [
35
                'fieldName' => IpAddressFieldInterface::PROP_IP_ADDRESS,
36
                'type'      => Type::STRING,
37
                'default'   => IpAddressFieldInterface::DEFAULT_IP_ADDRESS,
38
            ]
39
        );
40
        $fieldBuilder
41
            ->columnName(MappingHelper::getColumnNameForField(IpAddressFieldInterface::PROP_IP_ADDRESS))
42
            ->nullable(true)
43
            ->unique(false)
44
            ->length(45)
45
            ->build();
46
    }
47
48
    /**
49
     * This method sets the validation for this field.
50
     *
51
     * You should add in as many relevant property constraints as you see fit.
52
     *
53
     * @see https://symfony.com/doc/current/validation.html#supported-constraints
54
     *
55
     * @param ValidatorClassMetaData $metadata
56
     *
57
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
58
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
59
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
60
     */
61
    protected static function validatorMetaForPropertyIpAddress(ValidatorClassMetaData $metadata): void
62
    {
63
        $metadata->addPropertyConstraint(
64
            IpAddressFieldInterface::PROP_IP_ADDRESS,
65
            new Ip(IpAddressFieldInterface::IP_ADDRESS_VALIDATION_OPTIONS)
66
        );
67
    }
68
69
    /**
70
     * @return string|null
71
     */
72
    public function getIpAddress(): ?string
73
    {
74
        if (null === $this->ipAddress) {
75
            return IpAddressFieldInterface::DEFAULT_IP_ADDRESS;
76
        }
77
78
        return $this->ipAddress;
79
    }
80
81
    /**
82
     * @param string|null $ipAddress
83
     *
84
     * @return self
85
     */
86
    private function setIpAddress(?string $ipAddress): self
87
    {
88
        $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

88
        $this->/** @scrutinizer ignore-call */ 
89
               updatePropertyValue(
Loading history...
89
            IpAddressFieldInterface::PROP_IP_ADDRESS,
90
            $ipAddress
91
        );
92
93
        return $this;
94
    }
95
}
96