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 (#59)
by joseph
18:36
created

EmailAddressFieldTrait::getEmailAddress()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1
cc 2
nc 2
nop 0
crap 2
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String;
4
5
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\String\EmailAddressFieldInterface;
7
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ValidatedEntityInterface;
8
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
9
use Symfony\Component\Validator\Constraints\Email;
10
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
11
12
trait EmailAddressFieldTrait
13
{
14
15
    /**
16
     * @var string|null
17
     */
18
    private $emailAddress;
19
20
    /**
21
     * @SuppressWarnings(PHPMD.StaticAccess)
22
     * @param ClassMetadataBuilder $builder
23
     */
24 1
    public static function metaForEmailAddress(ClassMetadataBuilder $builder): void
25
    {
26 1
        MappingHelper::setSimpleStringFields(
27 1
            [EmailAddressFieldInterface::PROP_EMAIL_ADDRESS],
28 1
            $builder,
29 1
            EmailAddressFieldInterface::DEFAULT_EMAIL_ADDRESS,
30 1
            false
31
        );
32 1
    }
33
34
    /**
35
     * This method sets the validation for this field.
36
     *
37
     * You should add in as many relevant property constraints as you see fit.
38
     *
39
     * @see https://symfony.com/doc/current/validation.html#supported-constraints
40
     *
41
     * @param ValidatorClassMetaData $metadata
42
     *
43
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
44
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
45
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
46
     */
47 2
    protected static function validatorMetaForEmailAddress(ValidatorClassMetaData $metadata)
48
    {
49 2
        $metadata->addPropertyConstraint(
50 2
            EmailAddressFieldInterface::PROP_EMAIL_ADDRESS,
51 2
            new Email()
52
        );
53 2
    }
54
55
    /**
56
     * @return string|null
57
     */
58 2
    public function getEmailAddress(): ?string
59
    {
60 2
        if (null === $this->emailAddress) {
61 1
            return EmailAddressFieldInterface::DEFAULT_EMAIL_ADDRESS;
62
        }
63
64 2
        return $this->emailAddress;
65
    }
66
67
    /**
68
     * @param string|null $emailAddress
69
     *
70
     * @return self
71
     */
72 2
    public function setEmailAddress(?string $emailAddress): self
73
    {
74 2
        $this->emailAddress = $emailAddress;
75 2
        if ($this instanceof ValidatedEntityInterface) {
76 2
            $this->validateProperty(EmailAddressFieldInterface::PROP_EMAIL_ADDRESS);
77
        }
78
79 2
        return $this;
80
    }
81
}
82