Passed
Pull Request — master (#22)
by Nico
18:37 queued 03:42
created

ExpressionFactory::createFromOperator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 12
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 14
ccs 2
cts 2
cp 1
crap 1
rs 9.8666
1
<?php declare(strict_types=1);
2
3
/**
4
 * @license     http://opensource.org/licenses/mit-license.php MIT
5
 * @link        https://github.com/nicoSWD
6
 * @author      Nicolas Oelgart <[email protected]>
7
 */
8
namespace nicoSWD\Rule\Expression;
9
10
use nicoSWD\Rule\Parser\Exception\ParserException;
0 ignored issues
show
Bug introduced by
The type nicoSWD\Rule\Parser\Exception\ParserException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use nicoSWD\Rule\TokenStream\Token;
12
use nicoSWD\Rule\TokenStream\Token\Type\Operator;
13
14
final class ExpressionFactory implements ExpressionFactoryInterface
15
{
16
    /** @throws ParserException */
17
    public function createFromOperator(Operator $operator): BaseExpression
18
    {
19
        return match ($operator::class) {
20
            Token\TokenEqual::class => new EqualExpression(),
21
            Token\TokenEqualStrict::class => new EqualStrictExpression(),
22
            Token\TokenNotEqual::class => new NotEqualExpression(),
23
            Token\TokenNotEqualStrict::class => new NotEqualStrictExpression(),
24
            Token\TokenGreater::class => new GreaterThanExpression(),
25
            Token\TokenSmaller::class => new LessThanExpression(),
26
            Token\TokenSmallerEqual::class => new LessThanEqualExpression(),
27
            Token\TokenGreaterEqual::class => new GreaterThanEqualExpression(),
28 218
            Token\TokenIn::class => new InExpression(),
29
            Token\TokenNotIn::class => new NotInExpression(),
30 218
            default => throw ParserException::unknownOperator($operator),
31
        };
32
    }
33
}
34