Percentage::__invoke()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 12
cts 12
cp 1
rs 9.2
cc 4
eloc 9
nc 4
nop 3
crap 4
1
<?php
2
3
namespace Undemanding\Difference\Calculation;
4
5
class Percentage
6
{
7
    /**
8
     * Percentage of different pixels in the bitmap.
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
        $total = 0;
19 1
        $different = 0;
20
21 1
        for ($y = 0; $y < $height; $y++) {
22 1
            for ($x = 0; $x < $width; $x++) {
23 1
                $total++;
24
25 1
                if ($bitmap[$y][$x] > 0) {
26 1
                    $different++;
27 1
                }
28 1
            }
29 1
        }
30
31 1
        return (float) (($different / $total) * 100);
32
    }
33
}
34