Average::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 3
crap 3
1
<?php
2
3
namespace Undemanding\Difference\Calculation;
4
5
class Average
6
{
7
    /**
8
     * Average difference for all bitmap pixels.
9
     *
10
     * @param array $bitmap
11
     * @param int $width
12
     * @param int $height
13
     *
14
     * @return float
15
     */
16 1
    public function __invoke(array $bitmap, $width, $height)
17
    {
18 1
        $average = 0;
19
20 1
        for ($y = 0; $y < $height; $y++) {
21 1
            for ($x = 0; $x < $width; $x++) {
22 1
                $average += $bitmap[$y][$x];
23 1
            }
24 1
        }
25
26 1
        $average /= ($width * $height);
27
28 1
        return (float) $average;
29
    }
30
}
31