Passed
Pull Request — master (#130)
by Marcin
07:14
created

CompareStrategyFactory   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 9
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C create() 0 25 11
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Phpml\Strategy\Compare;
6
7
use Phpml\Exception\InvalidArgumentException;
8
9
class CompareStrategyFactory
10
{
11
    /**
12
     * @param string $operator
13
     *
14
     * @return CompareStrategy
15
     *
16
     * @throws InvalidArgumentException
17
     */
18
    public static function create(string $operator): CompareStrategy
19
    {
20
        switch ($operator) {
21
            case '>':
22
                return new GreaterThan();
23
            case '>=':
24
                return new GreaterThanOrEqual();
25
            case '=':
26
            case '==':
27
                return new EqualTo();
28
            case '===':
29
                return new IdenticalTo();
30
            case '<=':
31
                return new LessThanOrEqual();
32
            case '<':
33
                return new LessThan();
34
            case '!=':
35
            case '<>':
36
                return new NotEqualTo();
37
            case '!==':
38
                return new NotIdenticalTo();
39
            default:
40
                throw InvalidArgumentException::invalidOperator($operator);
41
        }
42
    }
43
}
44