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   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 60
ccs 15
cts 20
cp 0.75
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validatorMetaForPrice() 0 5 1
A metaForPrice() 0 6 1
A setPrice() 0 8 2
A getPrice() 0 7 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