Make `AndX`/`OrX` constructor parameter variadic (#1035) · yiisoft/db@75c1ad1

File tree

4 files changed

lines changed

  • tests/Db/QueryBuilder/Condition

4 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -465,7 +465,7 @@ public function createConditionFromArray(array $condition): ConditionInterface

465465

$conditions[] = new Condition\Equals($column, $value);

466466

}

467467
468-

return count($conditions) === 1 ? $conditions[0] : new Condition\AndX($conditions);

468+

return count($conditions) === 1 ? $conditions[0] : new Condition\AndX(...$conditions);

469469

}

470470
471471

public function getExpressionBuilder(ExpressionInterface $expression): object

Original file line numberDiff line numberDiff line change

@@ -12,18 +12,22 @@

1212

final class AndX implements ConditionInterface

1313

{

1414

/**

15-

* @param array $expressions The expressions that are connected by this condition.

16-

*

17-

* @psalm-param array<array|ExpressionInterface|scalar> $expressions

15+

* @psalm-var array<array|ExpressionInterface|scalar>

16+

*/

17+

public readonly array $expressions;

18+
19+

/**

20+

* @param array|bool|ExpressionInterface|float|int|string ...$expressions The expressions that are connected by this condition.

1821

*/

1922

public function __construct(

20-

public readonly array $expressions,

23+

array|ExpressionInterface|int|float|bool|string ...$expressions,

2124

) {

25+

$this->expressions = $expressions;

2226

}

2327
2428

public static function fromArrayDefinition(string $operator, array $operands): self

2529

{

2630

/** @psalm-var array<array|ExpressionInterface|scalar> $operands */

27-

return new self($operands);

31+

return new self(...$operands);

2832

}

2933

}

Original file line numberDiff line numberDiff line change

@@ -12,18 +12,22 @@

1212

final class OrX implements ConditionInterface

1313

{

1414

/**

15-

* @param array $expressions The expressions that are connected by this condition.

16-

*

17-

* @psalm-param array<array|ExpressionInterface|scalar> $expressions

15+

* @psalm-var array<array|ExpressionInterface|scalar>

16+

*/

17+

public readonly array $expressions;

18+
19+

/**

20+

* @param array|bool|ExpressionInterface|float|int|string ...$expressions The expressions that are connected by this condition.

1821

*/

1922

public function __construct(

20-

public readonly array $expressions,

23+

array|ExpressionInterface|int|float|bool|string ...$expressions,

2124

) {

25+

$this->expressions = $expressions;

2226

}

2327
2428

public static function fromArrayDefinition(string $operator, array $operands): self

2529

{

2630

/** @psalm-var array<array|ExpressionInterface|scalar> $operands */

27-

return new self($operands);

31+

return new self(...$operands);

2832

}

2933

}

Original file line numberDiff line numberDiff line change

@@ -14,8 +14,8 @@ final class AndXTest extends TestCase

1414

{

1515

public function testConstructor(): void

1616

{

17-

$andCondition = new AndX(['a' => 1, 'b' => 2]);

17+

$andCondition = new AndX(['a' => 1], ['b' => 2]);

1818
19-

$this->assertSame(['a' => 1, 'b' => 2], $andCondition->expressions);

19+

$this->assertSame([['a' => 1], ['b' => 2]], $andCondition->expressions);

2020

}

2121

}