StandardDeviation::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 6
Ratio 37.5 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 16
ccs 11
cts 11
cp 1
rs 9.4285
cc 3
eloc 9
nc 3
nop 4
crap 3
1
<?php
2
3
namespace Undemanding\Difference\Calculation;
4
5
class StandardDeviation
6
{
7
    /**
8
     * Standard deviation for all bitmap pixels.
9
     *
10
     * @param array $map
11
     * @param int $width
12
     * @param int $height
13
     * @param float $average
14
     *
15
     * @return float
16
     */
17 1
    public function __invoke(array $map, $width, $height, $average)
18
    {
19 1
        $standardDeviation = 0;
20
21 1 View Code Duplication
        for ($y = 0; $y < $height; $y++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22 1
            for ($x = 0; $x < $width; $x++) {
23 1
                $delta = $map[$y][$x] - $average;
24 1
                $standardDeviation += ($delta * $delta);
25 1
            }
26 1
        }
27
28 1
        $standardDeviation /= (($width * $height) - 1);
29 1
        $standardDeviation = sqrt($standardDeviation);
30
31 1
        return (float) $standardDeviation;
32
    }
33
}
34