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

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