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 ( f20003...f7764e )
by Ross
17s queued 11s
created

FloatWithinRangeFieldTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 73
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFloatWithinRange() 0 7 2
A metaForFloatWithinRange() 0 6 1
A validatorMetaForPropertyFloatWithinRange() 0 10 1
A setFloatWithinRange() 0 8 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\Numeric;
4
5
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\Numeric\FloatWithinRangeFieldInterface;
7
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
8
use Symfony\Component\Validator\Constraints\Range;
9
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
10
11
trait FloatWithinRangeFieldTrait
12
{
13
14
    /**
15
     * @var float|null
16
     */
17
    private $floatWithinRange;
18
19
    /**
20
     * @SuppressWarnings(PHPMD.StaticAccess)
21
     */
22
    public static function metaForFloatWithinRange(ClassMetadataBuilder $builder): void
23
    {
24
        MappingHelper::setSimpleFloatFields(
25
            [FloatWithinRangeFieldInterface::PROP_FLOAT_WITHIN_RANGE],
26
            $builder,
27
            FloatWithinRangeFieldInterface::DEFAULT_FLOAT_WITHIN_RANGE
28
        );
29
    }
30
31
    /**
32
     * @return float|null
33
     */
34
    public function getFloatWithinRange(): ?float
35
    {
36
        if (null === $this->floatWithinRange) {
37
            return FloatWithinRangeFieldInterface::DEFAULT_FLOAT_WITHIN_RANGE;
38
        }
39
40
        return $this->floatWithinRange;
41
    }
42
43
    /**
44
     * This method sets the validation for this field.
45
     *
46
     * You should add in as many relevant property constraints as you see fit.
47
     *
48
     * @see https://symfony.com/doc/current/validation.html#supported-constraints
49
     *
50
     * @param ValidatorClassMetaData $metadata
51
     *
52
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
53
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
54
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
55
     */
56
    protected static function validatorMetaForPropertyFloatWithinRange(ValidatorClassMetaData $metadata): void
57
    {
58
        $metadata->addPropertyConstraint(
59
            FloatWithinRangeFieldInterface::PROP_FLOAT_WITHIN_RANGE,
60
            new Range(
61
                [
62
                    'min'        => FloatWithinRangeFieldInterface::MIN_FLOAT_WITHIN_RANGE,
63
                    'max'        => FloatWithinRangeFieldInterface::MAX_FLOAT_WITHIN_RANGE,
64
                    'minMessage' => FloatWithinRangeFieldInterface::MIN_MESSAGE_FLOAT_WITHIN_RANGE,
65
                    'maxMessage' => FloatWithinRangeFieldInterface::MAX_MESSAGE_FLOAT_WITHIN_RANGE,
66
                ]
67
            )
68
        );
69
    }
70
71
    /**
72
     * @param float|null $floatWithinRange
73
     *
74
     * @return self
75
     */
76
    private function setFloatWithinRange(?float $floatWithinRange): self
77
    {
78
        $this->updatePropertyValue(
0 ignored issues
show
Bug introduced by
It seems like updatePropertyValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
        $this->/** @scrutinizer ignore-call */ 
79
               updatePropertyValue(
Loading history...
79
            FloatWithinRangeFieldInterface::PROP_FLOAT_WITHIN_RANGE,
80
            $floatWithinRange
81
        );
82
83
        return $this;
84
    }
85
}
86