Passed
Push — master ( 461a97...e7ae09 )
by SignpostMarv
02:31
created

HasMinMaxValue::SetMaxValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
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\SchemaOrg\TypeUtilities;
12
13
trait HasMinMaxValue
14
{
15
    use DaftObjectTrait;
16
17
    /**
18
    * @return array<int, float|int>
19
    */
20
    public function GetMaxValue() : array
21
    {
22
        /**
23
        * @var array<int, float|int>
24
        */
25
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
26
            'maxValue',
27
            $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
            static::class
29
        );
30
31
        return $out;
32
    }
33
34
    /**
35
    * @param array<int, float|int> $value
36
    */
37
    public function SetMaxValue(array $value) : void
38
    {
39
        $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
    }
41
42
    /**
43
    * @return array<int, float|int>
44
    */
45
    public function GetMinValue() : array
46
    {
47
        /**
48
        * @var array<int, float|int>
49
        */
50
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
51
            'minValue',
52
            $this->RetrievePropertyValueFromData('minValue'),
53
            static::class
54
        );
55
56
        return $out;
57
    }
58
59
    /**
60
    * @param array<int, float|int> $value
61
    */
62
    public function SetMinValue(array $value) : void
63
    {
64
        $this->NudgePropertyWithUniqueIntegersOrFloats('minValue', __METHOD__, $value);
65
    }
66
67
    /**
68
    * @return array<int, bool|string|int|float|StructuredValue>
69
    */
70
    public function GetValue() : array
71
    {
72
        /**
73
        * @var array<int, bool|string|int|float|StructuredValue>
74
        */
75
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
76
            'value',
77
            $this->RetrievePropertyValueFromData('value'),
78
            static::class
79
        );
80
81
        return $out;
82
    }
83
84
    /**
85
    * @param array<int, bool|string|int|float|StructuredValue> $value
86
    */
87
    public function SetValue(array $value) : void
88
    {
89
        $initialCount = count($value);
90
91
        /**
92
        * @var array<int, bool|string|int|float|StructuredValue>
93
        */
94
        $value = array_filter(
95
            $value,
96
            /**
97
            * @param mixed $maybe
98
            */
99
            function ($maybe) : bool {
100
                return
101
                    is_bool($maybe) ||
102
                    is_string($maybe) ||
103
                    is_float($maybe) ||
104
                    is_int($maybe) ||
105
                    ($maybe instanceof StructuredValue);
106
            }
107
        );
108
109
        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
        $this->NudgePropertyValue('value', $value);
120
    }
121
}
122