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 (#51)
by joseph
102:38 queued 99:24
created

NameFieldTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 41.18%

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 59
c 0
b 0
f 0
ccs 7
cts 17
cp 0.4118
rs 10

4 Methods

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