Skip to content

Commit 0ae9efd

Browse files
Clean code ArrayExpressionBuilder::class. (#246)
1 parent f001103 commit 0ae9efd

1 file changed

Lines changed: 29 additions & 29 deletions

File tree

src/Builder/ArrayExpressionBuilder.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use function str_repeat;
2424

2525
/**
26-
* The class ArrayExpressionBuilder builds {@see ArrayExpression} for PostgresSQL DBMS.
26+
* Builds expressions for {@see `Yiisoft\Db\Expression\ArrayExpression`} for PostgresSQL Server.
2727
*/
2828
final class ArrayExpressionBuilder implements ExpressionBuilderInterface
2929
{
@@ -32,21 +32,23 @@ public function __construct(private QueryBuilderInterface $queryBuilder)
3232
}
3333

3434
/**
35-
* Method builds the raw SQL from the $expression that will not be additionally escaped or quoted.
35+
* Method builds the raw SQL from the expression that will not be additionally escaped or quoted.
3636
*
37-
* @param ExpressionInterface $expression the expression to be built.
38-
* @param array $params the binding parameters.
37+
* @param ExpressionInterface $expression The expression to be built.
38+
* @param array $params The binding parameters.
3939
*
40-
* @throws Exception|InvalidArgumentException|InvalidConfigException|NotSupportedException
40+
* @throws Exception
41+
* @throws InvalidArgumentException
42+
* @throws InvalidConfigException
43+
* @throws NotSupportedException
4144
*
42-
* @return string the raw SQL that will not be additionally escaped or quoted.
45+
* @return string The raw SQL that will not be additionally escaped or quoted.
46+
*
47+
* @psalm-param ArrayExpression $expression
4348
*/
4449
public function build(ExpressionInterface $expression, array &$params = []): string
4550
{
46-
/**
47-
* @var ArrayExpression $expression
48-
* @var array|mixed|QueryInterface $value
49-
*/
51+
/** @psalm-var array|mixed|QueryInterface $value */
5052
$value = $expression->getValue();
5153

5254
if ($value === null) {
@@ -58,7 +60,7 @@ public function build(ExpressionInterface $expression, array &$params = []): str
5860
return $this->buildSubqueryArray($sql, $expression);
5961
}
6062

61-
/** @psalm-var string[] */
63+
/** @psalm-var string[] $placeholders */
6264
$placeholders = $this->buildPlaceholders($expression, $params);
6365

6466
return 'ARRAY[' . implode(', ', $placeholders) . ']' . $this->getTypehint($expression);
@@ -67,33 +69,35 @@ public function build(ExpressionInterface $expression, array &$params = []): str
6769
/**
6870
* Builds placeholders array out of $expression values.
6971
*
70-
* @param array $params the binding parameters.
72+
* @param array $params The binding parameters.
73+
*
74+
* @throws Exception
75+
* @throws InvalidArgumentException
76+
* @throws InvalidConfigException
77+
* @throws NotSupportedException
7178
*
72-
* @throws Exception|InvalidArgumentException|InvalidConfigException|NotSupportedException
79+
* @psalm-param ArrayExpression $expression
7380
*/
7481
protected function buildPlaceholders(ExpressionInterface $expression, array &$params): array
7582
{
7683
$placeholders = [];
7784

78-
/**
79-
* @var ArrayExpression $expression
80-
* @var mixed $value
81-
*/
85+
/** @psalm-var mixed $value */
8286
$value = $expression->getValue();
8387

8488
if (!is_array($value) && !$value instanceof Traversable) {
8589
return $placeholders;
8690
}
8791

8892
if ($expression->getDimension() > 1) {
89-
/** @var ExpressionInterface|int $item */
93+
/** @psalm-var ExpressionInterface|int $item */
9094
foreach ($value as $item) {
9195
$placeholders[] = $this->build($this->unnestArrayExpression($expression, $item), $params);
9296
}
9397
return $placeholders;
9498
}
9599

96-
/** @var ExpressionInterface|int $item */
100+
/** @psalm-var ExpressionInterface|int $item */
97101
foreach ($value as $item) {
98102
if ($item instanceof QueryInterface) {
99103
[$sql, $params] = $this->queryBuilder->build($item, $params);
@@ -114,16 +118,13 @@ protected function buildPlaceholders(ExpressionInterface $expression, array &$pa
114118
return $placeholders;
115119
}
116120

117-
/**
118-
* @param array|mixed|QueryInterface $value
119-
*/
120121
private function unnestArrayExpression(ArrayExpression $expression, mixed $value): ArrayExpression
121122
{
122123
return new ArrayExpression($value, $expression->getType(), $expression->getDimension() - 1);
123124
}
124125

125126
/**
126-
* @return string the typecast expression based on {@see type}.
127+
* @return string The typecast expression based on {@see type}.
127128
*/
128129
protected function getTypeHint(ArrayExpression $expression): string
129130
{
@@ -141,21 +142,20 @@ protected function getTypeHint(ArrayExpression $expression): string
141142
}
142143

143144
/**
144-
* Build an array expression from a subquery SQL.
145+
* Build an array expression from a sub-query SQL.
145146
*
146-
* @param string $sql the subquery SQL.
147+
* @param string $sql The sub-query SQL.
148+
* @param ArrayExpression $expression The array expression.
147149
*
148-
* @return string the subquery array expression.
150+
* @return string The sub-query array expression.
149151
*/
150152
protected function buildSubqueryArray(string $sql, ArrayExpression $expression): string
151153
{
152154
return 'ARRAY(' . $sql . ')' . $this->getTypeHint($expression);
153155
}
154156

155157
/**
156-
* Casts $value to use in $expression.
157-
*
158-
* @return array|bool|ExpressionInterface|int|JsonExpression|string|null
158+
* @return array|bool|ExpressionInterface|int|JsonExpression|string|null The cast value or expression.
159159
*/
160160
protected function typecastValue(
161161
ArrayExpression $expression,

0 commit comments

Comments
 (0)