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 ( b24b89...149ff2 )
by joseph
12s
created

QtyFieldTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

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