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 ( 51c99d...a4bf8a )
by joseph
24s queued 11s
created

IpAddressFieldTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 78
rs 10
c 0
b 0
f 0
ccs 24
cts 24
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validatorMetaForIpAddress() 0 5 1
A getIpAddress() 0 7 2
A metaForIpAddress() 0 16 1
A setIpAddress() 0 8 2
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