MinMaxArrayIterator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 35
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A max() 0 4 1
A min() 0 4 1
A getRange() 0 8 2
1
<?php
2
namespace FilmTools\Commons;
3
4
use function FilmTools\MRounder\mfloor;
5
use function FilmTools\MRounder\mceil;
6
7
class MinMaxArrayIterator extends \ArrayIterator implements MinMaxInterface
8
{
9
    protected $range_steps = 0.1;
10
11 21
    public function max()
12
    {
13 21
        return max( $this->getArrayCopy());
14
    }
15
16 48
    public function min()
17
    {
18 48
        return min( $this->getArrayCopy());
19
    }
20
21
    /**
22
     * Returns an range array from smallest to greatest exposure value.
23
     * The default step width is 0.1 and can be customized
24
     * with an optional method parameter.
25
     *
26
     * The minimum value is ceiled, and the maximum is floored,
27
     * to the next multiple of the used step width.
28
     *
29
     * @param  float $step Optional: custom range step width
30
     * @return \SplFixedArray
31
     */
32 12
    public function getRange( float $step = null) : \SplFixedArray
33
    {
34 12
        $step = is_null($step) ? $this->range_steps : $step;
35 12
        $min = mceil($this->min(), $step);
36 12
        $max = mfloor($this->max(), $step);
37
38 12
        return \SplFixedArray::fromArray( range($min, $max, $step));
39
    }
40
41
}
42