Passed
Push — master ( f8f76e...e5015c )
by Bas
12:29
created

TernaryExpression   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 13
c 4
b 0
f 0
dl 0
loc 34
ccs 12
cts 12
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compile() 0 9 1
A __construct() 0 5 1
1
<?php
2
3
namespace LaravelFreelancerNL\FluentAQL\Expressions;
4
5
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
6
7
class TernaryExpression extends Expression implements ExpressionInterface
8
{
9
    /** @var string */
10
    protected $predicates = [];
11
12
    /** @var string */
13
    protected $then = '';
14
15
    /** @var string */
16
    protected $else = '';
17
18
    /**
19
     * Create predicate expression.
20
     *
21
     * @param string $predicates
22
     * @param string $then
23
     * @param string $else
24
     */
25 1
    public function __construct($predicates, $then, $else = null)
26
    {
27 1
        $this->predicates = $predicates;
28 1
        $this->then = $then;
29 1
        $this->else = $else;
30 1
    }
31
32 1
    public function compile(QueryBuilder $queryBuilder): string
33
    {
34 1
        $this->predicates = $queryBuilder->normalizePredicates($this->predicates);
0 ignored issues
show
Documentation Bug introduced by
It seems like $queryBuilder->normalize...ates($this->predicates) of type array or array<mixed,array|array<...ay|array<mixed,mixed>>> is incompatible with the declared type string of property $predicates.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
Bug introduced by
$this->predicates of type string is incompatible with the type LaravelFreelancerNL\Flue...edicateExpression|array expected by parameter $predicates of LaravelFreelancerNL\Flue...::normalizePredicates(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        $this->predicates = $queryBuilder->normalizePredicates(/** @scrutinizer ignore-type */ $this->predicates);
Loading history...
35 1
        $this->then = $queryBuilder->normalizeArgument($this->then);
0 ignored issues
show
Documentation Bug introduced by
It seems like $queryBuilder->normalizeArgument($this->then) of type LaravelFreelancerNL\Flue...ressions\BindExpression is incompatible with the declared type string of property $then.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36 1
        $this->else = $queryBuilder->normalizeArgument($this->else);
0 ignored issues
show
Documentation Bug introduced by
It seems like $queryBuilder->normalizeArgument($this->else) of type LaravelFreelancerNL\Flue...ressions\BindExpression is incompatible with the declared type string of property $else.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
37
38 1
        return '(' . $queryBuilder->compilePredicates($this->predicates) . ')' .
39 1
            ' ? ' . $this->then->compile($queryBuilder) .
40 1
            ' : ' . $this->else->compile($queryBuilder);
41
    }
42
}
43