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 ( 647edc...edf045 )
by joseph
18s queued 16s
created

PriceFieldTrait::setPrice()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\Financial;
4
5
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\Financial\PriceFieldInterface;
7
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ValidatedEntityInterface;
8
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
9
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
10
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
11
12
trait PriceFieldTrait
13
{
14
    /**
15
     * @var float|null
16
     */
17
    private $price;
18
19
    /**
20
     * @SuppressWarnings(PHPMD.StaticAccess)
21
     * @param ClassMetadataBuilder $builder
22
     */
23 1
    public static function metaForPrice(ClassMetadataBuilder $builder): void
24
    {
25 1
        MappingHelper::setSimpleDecimalFields(
26 1
            [PriceFieldInterface::PROP_PRICE],
27 1
            $builder,
28 1
            PriceFieldInterface::DEFAULT_PRICE
29
        );
30 1
    }
31
32
    /**
33
     * @param ValidatorClassMetaData $metadata
34
     *
35
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
36
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
37
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
38
     */
39
    protected static function validatorMetaForPrice(ValidatorClassMetaData $metadata): void
40
    {
41
        $metadata->addPropertyConstraint(
42
            PriceFieldInterface::PROP_PRICE,
43
            new GreaterThanOrEqual(0)
44
        );
45
    }
46
47
    /**
48
     * @return float
49
     */
50 2
    public function getPrice(): float
51
    {
52 2
        if (null === $this->price) {
53 1
            return PriceFieldInterface::DEFAULT_PRICE;
54
        }
55
56 2
        return $this->price;
57
    }
58
59
    /**
60
     * @param float $price
61
     *
62
     * @return $this|PriceFieldInterface
63
     */
64 2
    public function setPrice(float $price): self
65
    {
66 2
        $this->price = $price;
67 2
        if ($this instanceof ValidatedEntityInterface) {
68 2
            $this->validateProperty(PriceFieldInterface::PROP_PRICE);
69
        }
70
71 2
        return $this;
72
    }
73
}
74