Completed
Push — master ( 906125...5fd544 )
by BENOIT
01:10
created

CompositeExpression::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace BenTools\Where\Expression;
5
6
final class CompositeExpression extends Expression
7
{
8
    /**
9
     * @var string
10
     */
11
    private $operator;
12
13
    /**
14
     * @var Expression[]
15
     */
16
    private $expressions = [];
17
18
    /**
19
     * CompositeExpression constructor.
20
     * @param string       $operator
21
     * @param Expression[] ...$expressions
22
     */
23
    protected function __construct(string $operator, Expression ...$expressions)
24
    {
25
        $this->operator = $operator;
26
        $this->expressions = $expressions;
0 ignored issues
show
Documentation Bug introduced by
It seems like $expressions of type array<integer,array<inte...xpression\Expression>>> is incompatible with the declared type array<integer,object<Ben...Expression\Expression>> of property $expressions.

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...
27
    }
28
29
    /**
30
     * @inheritDoc
31
     */
32
    public function __toString(): string
33
    {
34
        return implode(" {$this->operator} ", array_map(function (Expression $expression) {
35
            return (string) $expression;
36
        }, $this->expressions));
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42
    public function getValues(): array
43
    {
44
        $generator = function (Expression ...$expressions) {
45
            foreach ($expressions as $expression) {
46
                foreach ($expression->getValues() as $key => $value) {
47
                    if (is_numeric($key)) {
48
                        yield $value;
49
                    } else {
50
                        yield $key => $value;
51
                    }
52
                }
53
            }
54
        };
55
56
        return iterator_to_array($generator(...$this->expressions));
57
    }
58
}
59