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

UrlFieldTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUrl() 0 8 2
A validatorMetaForUrl() 0 5 1
A metaForUrl() 0 7 1
A getUrl() 0 7 2
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String;
4
5
// phpcs:disable
6
7
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\String\UrlFieldInterface;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ValidatedEntityInterface;
10
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
11
use Symfony\Component\Validator\Constraints\Url;
12
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
13
14
// phpcs:enable
15
trait UrlFieldTrait
16
{
17
18
    /**
19
     * @var string|null
20
     */
21
    private $url;
22
23
    /**
24
     * @SuppressWarnings(PHPMD.StaticAccess)
25
     * @param ClassMetadataBuilder $builder
26
     */
27 1
    public static function metaForUrl(ClassMetadataBuilder $builder): void
28
    {
29 1
        MappingHelper::setSimpleStringFields(
30 1
            [UrlFieldInterface::PROP_URL],
31 1
            $builder,
32 1
            UrlFieldInterface::DEFAULT_URL,
33 1
            false
34
        );
35 1
    }
36
37
    /**
38
     * This method sets the validation for this field.
39
     *
40
     * You should add in as many relevant property constraints as you see fit.
41
     *
42
     * Remove the PHPMD suppressed warning once you start setting constraints
43
     *
44
     * @see https://symfony.com/doc/current/validation.html#supported-constraints
45
     *
46
     * @param ValidatorClassMetaData $metadata
47
     *
48
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
49
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
50
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
51
     */
52 2
    protected static function validatorMetaForUrl(ValidatorClassMetaData $metadata)
53
    {
54 2
        $metadata->addPropertyConstraint(
55 2
            UrlFieldInterface::PROP_URL,
56 2
            new Url()
57
        );
58 2
    }
59
60
    /**
61
     * @return string|null
62
     */
63 2
    public function getUrl(): ?string
64
    {
65 2
        if (null === $this->url) {
66 1
            return UrlFieldInterface::DEFAULT_URL;
67
        }
68
69 2
        return $this->url;
70
    }
71
72
    /**
73
     * @param string|null $url
74
     *
75
     * @return self
76
     */
77 2
    public function setUrl(?string $url): self
78
    {
79 2
        $this->url = $url;
80 2
        if ($this instanceof ValidatedEntityInterface) {
81 2
            $this->validateProperty(UrlFieldInterface::PROP_URL);
82
        }
83
84 2
        return $this;
85
    }
86
}
87