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 ( 69b831...bd71a5 )
by joseph
20:49 queued 13s
created

UrlFieldTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 95.83%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 74
ccs 23
cts 24
cp 0.9583
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUrl() 0 8 1
A validatorMetaForPropertyUrl() 0 13 1
A metaForUrl() 0 6 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\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 6
    public static function metaForUrl(ClassMetadataBuilder $builder): void
29
    {
30 6
        MappingHelper::setSimpleStringFields(
31 6
            [UrlFieldInterface::PROP_URL],
32 6
            $builder,
33 6
            UrlFieldInterface::DEFAULT_URL
34
        );
35 6
    }
36
37
    /**
38
     * This method validates that the url is valid
39
     *
40
     * It allows the protocol to be ommitted, eg //www.edmondscommerce.co.uk
41
     *
42
     * You can extend the list of allowed protocols as you see fit
43
     *
44
     * @param ValidatorClassMetaData $metadata
45
     */
46 6
    protected static function validatorMetaForPropertyUrl(ValidatorClassMetaData $metadata): void
47
    {
48 6
        $metadata->addPropertyConstraints(
49 6
            UrlFieldInterface::PROP_URL,
50
            [
51 6
                new Url([
52 6
                        'relativeProtocol' => true,
53
                        'protocols'        => ['http', 'https'],
54
                    ]),
55 6
                new Length(
56
                    [
57 6
                        'min' => 1,
58
                        'max' => Database::MAX_VARCHAR_LENGTH,
59
                    ]
60
                ),
61
            ]
62
        );
63 6
    }
64
65
    /**
66
     * @return string|null
67
     */
68 6
    public function getUrl(): ?string
69
    {
70 6
        if (null === $this->url) {
71 6
            return UrlFieldInterface::DEFAULT_URL;
72
        }
73
74 6
        return $this->url;
75
    }
76
77
    /**
78
     * @param string|null $url
79
     *
80
     * @return self
81
     */
82 6
    private function setUrl(?string $url): self
83
    {
84 6
        $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

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