Completed
Push — develop ( 9c8340...aed37e )
by Arkadiusz
02:48
created

Chebyshev::distance()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %
Metric Value
dl 15
loc 15
rs 9.4285
cc 3
eloc 8
nc 3
nop 2
1
<?php
2
3
declare (strict_types = 1);
4
5
namespace Phpml\Metric\Distance;
6
7
use Phpml\Exception\InvalidArgumentException;
8
use Phpml\Metric\Distance;
9
10 View Code Duplication
class Chebyshev implements Distance
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
11
{
12
    /**
13
     * @param array $a
14
     * @param array $b
15
     *
16
     * @return float
17
     *
18
     * @throws InvalidArgumentException
19
     */
20
    public function distance(array $a, array $b): float
21
    {
22
        if (count($a) !== count($b)) {
23
            throw InvalidArgumentException::sizeNotMatch();
24
        }
25
26
        $differences = [];
27
        $count = count($a);
28
29
        for ($i = 0; $i < $count; ++$i) {
30
            $differences[] = abs($a[$i] - $b[$i]);
31
        }
32
33
        return max($differences);
34
    }
35
}
36