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 (#47)
by joseph
07:51 queued 05:21
created

getPropertyValidatorMetaForLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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
    protected static function metaForLabel(ClassMetadataBuilder $builder): void
22
    {
23
        $builder->createField(LabelFieldInterface::PROP_LABEL, Type::STRING)
24
                ->nullable(true)
25
                ->length(255)
26
                ->build();
27
    }
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
    public function getLabel(): ?string
55
    {
56
        return $this->label;
57
    }
58
59
    /**
60
     * Set label
61
     *
62
     * @param string $label
63
     *
64
     * @return $this
65
     */
66
    public function setLabel(?string $label): self
67
    {
68
        $this->label = $label;
69
        if ($this instanceof ValidatedEntityInterface) {
70
            $this->validateProperty(LabelFieldInterface::PROP_LABEL);
71
        }
72
73
        return $this;
74
    }
75
}
76