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 ( 08e101...6f7bef )
by joseph
23:56 queued 01:38
created

UrlFieldTrait::validatorMetaForPropertyUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 13
ccs 0
cts 13
cp 0
crap 2
rs 10
c 1
b 0
f 0
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\MappingHelper;
10
use EdmondsCommerce\DoctrineStaticMeta\Schema\Database;
11
use Symfony\Component\Validator\Constraints\Length;
12
use Symfony\Component\Validator\Constraints\Url;
13
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
14
15
// phpcs:enable
16
trait UrlFieldTrait
17
{
18
19
    /**
20
     * @var string|null
21
     */
22
    private $url;
23
24
    /**
25
     * @SuppressWarnings(PHPMD.StaticAccess)
26
     * @param ClassMetadataBuilder $builder
27
     */
28
    public static function metaForUrl(ClassMetadataBuilder $builder): void
29
    {
30
        MappingHelper::setSimpleStringFields(
31
            [UrlFieldInterface::PROP_URL],
32
            $builder,
33
            UrlFieldInterface::DEFAULT_URL,
34
            false
35
        );
36
    }
37
38
    /**
39
     * This method validates that the url is valid
40
     *
41
     * It allows the protocol to be ommitted, eg //www.edmondscommerce.co.uk
42
     *
43
     * You can extend the list of allowed protocols as you see fit
44
     */
45
    protected static function validatorMetaForPropertyUrl(ValidatorClassMetaData $metadata): void
46
    {
47
        $metadata->addPropertyConstraints(
48
            UrlFieldInterface::PROP_URL,
49
            [
50
                new Url([
51
                        'relativeProtocol' => true,
52
                        'protocols'        => ['http', 'https'],
53
                    ]),
54
                new Length(
55
                    [
56
                        'min' => 1,
57
                        'max' => Database::MAX_VARCHAR_LENGTH,
58
                    ]
59
                ),
60
            ]
61
        );
62
    }
63
64
    /**
65
     * @return string|null
66
     */
67
    public function getUrl(): ?string
68
    {
69
        if (null === $this->url) {
70
            return UrlFieldInterface::DEFAULT_URL;
71
        }
72
73
        return $this->url;
74
    }
75
76
    /**
77
     * @param string|null $url
78
     *
79
     * @return self
80
     */
81
    private function setUrl(?string $url): self
82
    {
83
        $this->updatePropertyValue(
0 ignored issues
show
Bug introduced by
It seems like updatePropertyValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
        $this->/** @scrutinizer ignore-call */ 
84
               updatePropertyValue(
Loading history...
84
            UrlFieldInterface::PROP_URL,
85
            $url
86
        );
87
88
        return $this;
89
    }
90
}
91