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

src/CompositeExpression.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
declare(strict_types=1);
3
4
namespace BenTools\Where;
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...ols\Where\Expression>>> is incompatible with the declared type array<integer,object<BenTools\Where\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