Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
5 / 10
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ExpressionGroup
50.00% covered (danger)
50.00%
5 / 10
50.00% covered (danger)
50.00%
2 / 4
10.50
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 add
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getType
n/a
0 / 0
n/a
0 / 0
0
 toSql
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 toGeneralizedSql
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Wikimedia\Rdbms;
4
5use InvalidArgumentException;
6use Wikimedia\Rdbms\Database\DbQuoter;
7
8/**
9 * A composite node representing a group of expressions.
10 *
11 * @since 1.42
12 */
13abstract class ExpressionGroup implements IExpression {
14    /**
15     * @var IExpression[]
16     */
17    protected array $children = [];
18
19    /**
20     * @internal
21     * @param IExpression ...$children
22     */
23    public function __construct( IExpression ...$children ) {
24        $this->children = $children;
25    }
26
27    final protected function add( IExpression $expression ) {
28        $this->children[] = $expression;
29    }
30
31    abstract protected function getType(): string;
32
33    /**
34     * @param DbQuoter $dbQuoter
35     * @return string
36     * @return-taint none
37     */
38    final public function toSql( DbQuoter $dbQuoter ): string {
39        if ( !$this->children ) {
40            throw new InvalidArgumentException( "The array of values can't be empty." );
41        }
42        $sqls = array_map( static fn ( $value ) => $value->toSql( $dbQuoter ), $this->children );
43        return '(' . implode( ' ' . $this->getType() . ' ', $sqls ) . ')';
44    }
45
46    final public function toGeneralizedSql(): string {
47        if ( !$this->children ) {
48            throw new InvalidArgumentException( "The array of values can't be empty." );
49        }
50        $sqls = array_map( static fn ( $value ) => $value->toGeneralizedSql(), $this->children );
51        return '(' . implode( ' ' . $this->getType() . ' ', $sqls ) . ')';
52    }
53}