Passed
Pull Request — master (#287)
by Marcin
02:51
created

Comparison   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 1
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B compare() 0 25 11
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Phpml\Math;
6
7
use Phpml\Exception\InvalidArgumentException;
8
9
class Comparison
10
{
11
    /**
12
     * @throws InvalidArgumentException
13
     */
14
    public static function compare($a, $b, string $operator): bool
15
    {
16
        switch ($operator) {
17
            case '>':
18
                return $a > $b;
19
            case '>=':
20
                return $a >= $b;
21
            case '=':
22
            case '==':
23
                return $a == $b;
24
            case '===':
25
                return $a === $b;
26
            case '<=':
27
                return $a <= $b;
28
            case '<':
29
                return $a < $b;
30
            case '!=':
31
            case '<>':
32
                return $a != $b;
33
            case '!==':
34
                return $a !== $b;
35
            default:
36
                throw new InvalidArgumentException(sprintf('Invalid operator "%s" provided', $operator));
37
        }
38
    }
39
}
40