Passed
Push — master ( 539757...2d32e6 )
by Carsten
05:57
created

MinMaxArrayIterator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
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 34
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 24
    public function max()
12
    {
13 24
        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 a third of log10(2) and can be customized
24
     * with an optional method parameter.
25
     *
26
     * The minimum value is ceiled, and the maximum is floored.
27
     *
28
     * @param  float $step Optional: custom range step width
29
     * @return \SplFixedArray
30
     */
31 12
    public function getRange( float $step = null) : \SplFixedArray
32
    {
33 12
        $step = $step ?: $this->range_steps;
34 12
        $min = mceil($this->min(), $step);
35 12
        $max = mfloor($this->max(), $step);
36
37 12
        return \SplFixedArray::fromArray( range($min, $max, $step));
38
    }
39
40
}
41