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 (#52)
by joseph
38:21 queued 34:31
created

LabelFieldTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 68.42%

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 60
ccs 13
cts 19
cp 0.6842
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setLabel() 0 8 2
A getLabel() 0 3 1
A validatorMetaForLabel() 0 8 1
A metaForLabel() 0 6 1
1
<?php declare(strict_types=1);
2
3
4
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\Attribute;
5
6
use Doctrine\DBAL\Types\Type;
7
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\Attribute\LabelFieldInterface;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
10
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ValidatedEntityInterface;
11
use Symfony\Component\Validator\Constraints\Length;
12
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
13
14
trait LabelFieldTrait
15
{
16
    /**
17
     * @var string
18
     */
19
    private $label;
20
21 1
    protected static function metaForLabel(ClassMetadataBuilder $builder): void
22
    {
23 1
        $builder->createField(LabelFieldInterface::PROP_LABEL, Type::STRING)
24 1
                ->nullable(true)
25 1
                ->length(255)
26 1
                ->build();
27 1
    }
28
29
    /**
30
     * @param ValidatorClassMetaData $metadata
31
     *
32
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
33
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
34
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
35
     */
36
    protected static function validatorMetaForLabel(ValidatorClassMetaData $metadata): void
37
    {
38
        $metadata->addPropertyConstraints(
39
            LabelFieldInterface::PROP_LABEL,
40
            [
41
                new Length([
42
                               'min' => 2,
43
                               'max' => 255,
44
                           ]),
45
            ]
46
        );
47
    }
48
49
    /**
50
     * Get label
51
     *
52
     * @return string
53
     */
54 2
    public function getLabel(): ?string
55
    {
56 2
        return $this->label;
57
    }
58
59
    /**
60
     * Set label
61
     *
62
     * @param string $label
63
     *
64
     * @return $this
65
     */
66 2
    public function setLabel(?string $label): self
67
    {
68 2
        $this->label = $label;
69 2
        if ($this instanceof ValidatedEntityInterface) {
70 2
            $this->validateProperty(LabelFieldInterface::PROP_LABEL);
71
        }
72
73 2
        return $this;
74
    }
75
}
76