Passed
Push — master ( 200b0a...77331f )
by SignpostMarv
03:55
created

HasMinMaxValue::GetMinValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 12
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
* @author SignpostMarv
4
*/
5
declare(strict_types=1);
6
7
namespace SignpostMarv\DaftObject\SchemaOrg\DaftObjectTraits;
8
9
use InvalidArgumentException;
10
use SignpostMarv\DaftObject\SchemaOrg\Intangible\StructuredValue;
11
use SignpostMarv\DaftObject\TypeUtilities;
12
13
trait HasMinMaxValue
14
{
15
    use DaftObjectTrait;
16
17
    /**
18
    * @return array<int, float|int>
19
    */
20 5
    public function GetMaxValue() : array
21
    {
22
        /**
23
        * @var array<int, float|int>
24
        */
25 5
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
26 5
            'maxValue',
27 5
            $this->RetrievePropertyValueFromData('maxValue'),
0 ignored issues
show
Bug introduced by
It seems like RetrievePropertyValueFromData() 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

27
            $this->/** @scrutinizer ignore-call */ 
28
                   RetrievePropertyValueFromData('maxValue'),
Loading history...
28 5
            static::class
29
        );
30
31 5
        return $out;
32
    }
33
34
    /**
35
    * @param array<int, float|int> $value
36
    */
37 3
    public function SetMaxValue(array $value) : void
38
    {
39 3
        $this->NudgePropertyWithUniqueIntegersOrFloats('maxValue', __METHOD__, $value);
0 ignored issues
show
Bug introduced by
The method NudgePropertyWithUniqueIntegersOrFloats() does not exist on SignpostMarv\DaftObject\...ctTraits\HasMinMaxValue. Did you maybe mean NudgePropertyWithUniqueValuesOfThings()? ( Ignorable by Annotation )

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

39
        $this->/** @scrutinizer ignore-call */ 
40
               NudgePropertyWithUniqueIntegersOrFloats('maxValue', __METHOD__, $value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40 3
    }
41
42
    /**
43
    * @return array<int, float|int>
44
    */
45 5
    public function GetMinValue() : array
46
    {
47
        /**
48
        * @var array<int, float|int>
49
        */
50 5
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
51 5
            'minValue',
52 5
            $this->RetrievePropertyValueFromData('minValue'),
53 5
            static::class
54
        );
55
56 5
        return $out;
57
    }
58
59
    /**
60
    * @param array<int, float|int> $value
61
    */
62 1
    public function SetMinValue(array $value) : void
63
    {
64 1
        $this->NudgePropertyWithUniqueIntegersOrFloats('minValue', __METHOD__, $value);
65 1
    }
66
67
    /**
68
    * @return array<int, bool|string|int|float|StructuredValue>
69
    */
70 5
    public function GetValue() : array
71
    {
72
        /**
73
        * @var array<int, string>
74
        */
75 5
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
76 5
            'value',
77 5
            $this->RetrievePropertyValueFromData('value'),
78 5
            static::class
79
        );
80
81 5
        return $out;
82
    }
83
84
    /**
85
    * @param array<int, bool|string|int|float|StructuredValue> $value
86
    */
87 3
    public function SetValue(array $value) : void
88
    {
89 3
        $initialCount = count($value);
90
91
        /**
92
        * @var array<int, bool|string|int|float|StructuredValue>
93
        */
94 3
        $value = array_filter(
95 3
            $value,
96
            /**
97
            * @param mixed $maybe
98
            */
99
            function ($maybe) : bool {
100
                return
101 2
                    is_bool($maybe) ||
102 2
                    is_string($maybe) ||
103 2
                    is_float($maybe) ||
104 2
                    is_int($maybe) ||
105 2
                    ($maybe instanceof StructuredValue);
106 3
            }
107
        );
108
109 3
        if (count($value) !== $initialCount) {
110
            throw new InvalidArgumentException(
111
                'Argument 1 passed to ' .
112
                __METHOD__ .
113
                ' must be an array of any combination of booleans, strings, floats, ints, and ' .
114
                StructuredValue::class .
115
                '!'
116
            );
117
        }
118
119 3
        $this->NudgePropertyValue('value', $value);
120 3
    }
121
}
122