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
Pull Request — master (#59)
by joseph
17:21
created

IsbnFieldTrait   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 getIsbn() 0 7 2
A setIsbn() 0 8 2
A metaForIsbn() 0 7 1
A validatorMetaForIsbn() 0 5 1
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\IsbnFieldInterface;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ValidatedEntityInterface;
10
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
11
use Symfony\Component\Validator\Constraints\Isbn;
12
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
13
14
// phpcs:enable
15
trait IsbnFieldTrait
16
{
17
18
    /**
19
     * @var string|null
20
     */
21
    private $isbn;
22
23
    /**
24
     * @SuppressWarnings(PHPMD.StaticAccess)
25
     * @param ClassMetadataBuilder $builder
26
     */
27 1
    public static function metaForIsbn(ClassMetadataBuilder $builder): void
28
    {
29 1
        MappingHelper::setSimpleStringFields(
30 1
            [IsbnFieldInterface::PROP_ISBN],
31 1
            $builder,
32 1
            IsbnFieldInterface::DEFAULT_ISBN,
33 1
            true
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 3
    protected static function validatorMetaForIsbn(ValidatorClassMetaData $metadata)
53
    {
54 3
        $metadata->addPropertyConstraint(
55 3
            IsbnFieldInterface::PROP_ISBN,
56 3
            new Isbn()
57
        );
58 3
    }
59
60
    /**
61
     * @return string|null
62
     */
63 2
    public function getIsbn(): ?string
64
    {
65 2
        if (null === $this->isbn) {
66 1
            return IsbnFieldInterface::DEFAULT_ISBN;
67
        }
68
69 2
        return $this->isbn;
70
    }
71
72
    /**
73
     * @param string|null $isbn
74
     *
75
     * @return self
76
     */
77 3
    public function setIsbn(?string $isbn): self
78
    {
79 3
        $this->isbn = $isbn;
80 3
        if ($this instanceof ValidatedEntityInterface) {
81 3
            $this->validateProperty(IsbnFieldInterface::PROP_ISBN);
82
        }
83
84 2
        return $this;
85
    }
86
}
87