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

MinMaxArrayIterator::getRange()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 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