Passed
Push — master ( 90d129...206775 )
by SignpostMarv
03:53
created

HasMinMaxValue   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Test Coverage

Coverage 81.58%

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 107
ccs 31
cts 38
cp 0.8158
rs 10
c 0
b 0
f 0
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A SetMaxValue() 0 3 1
A GetMaxValue() 0 12 1
A GetValue() 0 12 1
A SetMinValue() 0 3 1
A GetMinValue() 0 12 1
A SetValue() 0 33 6
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 1
    public function GetMaxValue() : array
21
    {
22
        /**
23
        * @var array<int, float|int>
24
        */
25 1
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
26 1
            'maxValue',
27 1
            $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 1
            static::class
29
        );
30
31 1
        return $out;
32
    }
33
34
    /**
35
    * @param array<int, float|int> $value
36
    */
37 1
    public function SetMaxValue(array $value) : void
38
    {
39 1
        $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 1
    }
41
42
    /**
43
    * @return array<int, float|int>
44
    */
45 1
    public function GetMinValue() : array
46
    {
47
        /**
48
        * @var array<int, float|int>
49
        */
50 1
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
51 1
            'minValue',
52 1
            $this->RetrievePropertyValueFromData('minValue'),
53 1
            static::class
54
        );
55
56 1
        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 1
    public function GetValue() : array
71
    {
72
        /**
73
        * @var array<int, string>
74
        */
75 1
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
76 1
            'value',
77 1
            $this->RetrievePropertyValueFromData('value'),
78 1
            static::class
79
        );
80
81 1
        return $out;
82
    }
83
84
    /**
85
    * @param array<int, bool|string|int|float|StructuredValue> $value
86
    */
87 1
    public function SetValue(array $value) : void
88
    {
89 1
        $initialCount = count($value);
90
91
        /**
92
        * @var array<int, bool|string|int|float|StructuredValue>
93
        */
94 1
        $value = array_filter(
95 1
            $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 1
            }
107
        );
108
109 1
        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 1
        $this->NudgePropertyValue('value', $value);
120 1
    }
121
}
122