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.
Passed
Pull Request — master (#47)
by joseph
02:29
created

IpAddressFieldTrait::validatorMetaForIpAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
4
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\Attribute;
5
6
use Doctrine\DBAL\Types\Type;
7
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\Attribute\IpAddressFieldInterface;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ValidatedEntityInterface;
10
use Symfony\Component\Validator\Constraints\Ip;
11
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
12
13
/**
14
 * Any valid IP address including version 4 and 6
15
 *
16
 * Trait IpAddressFieldTrait
17
 *
18
 * @package EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\Attribute
19
 */
20
trait IpAddressFieldTrait
21
{
22
23
24
    /**
25
     * @var string
26
     */
27
    private $ipAddress;
28
29
    /**
30
     * @see https://stackoverflow.com/a/1076755/543455
31
     *
32
     * @param ClassMetadataBuilder $builder
33
     */
34
    protected static function metaForIpAddress(ClassMetadataBuilder $builder): void
35
    {
36
        $builder->createField(IpAddressFieldInterface::PROP_IP_ADDRESS, Type::STRING)
37
                ->length(45)
38
                ->nullable(true)
39
                ->build();
40
    }
41
42
    /**
43
     * @see https://symfony.com/doc/current/reference/constraints/Ip.html
44
     *
45
     * @param ValidatorClassMetaData $metadata
46
     *
47
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
48
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
49
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
50
     */
51
    protected static function validatorMetaForIpAddress(ValidatorClassMetaData $metadata): void
52
    {
53
        $metadata->addPropertyConstraint(
54
            IpAddressFieldInterface::PROP_IP_ADDRESS,
55
            new Ip(static::IP_ADDRESS_VALIDATION_OPTIONS)
0 ignored issues
show
Bug introduced by
The constant EdmondsCommerce\Doctrine...RESS_VALIDATION_OPTIONS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
56
        );
57
    }
58
59
    /**
60
     * Get ipAddress
61
     *
62
     * @return string
63
     */
64
    public function getIpAddress(): ?string
65
    {
66
        return $this->ipAddress;
67
    }
68
69
    /**
70
     * Set ipAddress
71
     *
72
     * @param string $ipAddress
73
     *
74
     * @return $this
75
     */
76
    public function setIpAddress(?string $ipAddress): self
77
    {
78
        $this->ipAddress = $ipAddress;
79
        if ($this instanceof ValidatedEntityInterface) {
80
            $this->validateProperty(IpAddressFieldInterface::PROP_IP_ADDRESS);
81
        }
82
83
        return $this;
84
    }
85
}
86