Skip to content

Commit

Permalink
Update comments and remove null for $queryBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Apr 2, 2024
1 parent f8f226a commit 42c263e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/Expression/AbstractExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,23 @@
*/
abstract class AbstractExpressionBuilder implements ExpressionBuilderInterface
{
public function __construct(private QueryBuilderInterface|null $queryBuilder = null)
public function __construct(private QueryBuilderInterface $queryBuilder)
{
}

/**
* Builds SQL statement from the given expression.
* Builds an SQL expression from the given expression object.
*
* @param Expression $expression The expression to be built.
* This method is called by the query builder to build SQL expressions from {@see ExpressionInterface} objects.
*
* @param Expression $expression The expression to build.
* @param array $params The parameters to be bound to the query.
*
* @psalm-param ParamsType $params
*
* @return string SQL statement.
* @return string SQL expression.
*/
public function build(Expression $expression, array &$params = []): string
public function build(ExpressionInterface $expression, array &$params = []): string
{
$sql = $expression->__toString();
$expressionParams = $expression->getParams();
Expand All @@ -51,7 +53,7 @@ public function build(Expression $expression, array &$params = []): string
return $sql;
}

if ($this->queryBuilder === null || isset($expressionParams[0])) {
if (isset($expressionParams[0])) {
$params = array_merge($params, $expressionParams);
return $sql;
}
Expand Down Expand Up @@ -138,7 +140,6 @@ private function buildParamExpressions(array $expressionParams, array &$params):
}

$placeholder = $name[0] !== ':' ? ":$name" : $name;
/** @psalm-suppress PossiblyNullReference */
$replacements[$placeholder] = $this->queryBuilder->buildExpression($value, $params);

/** @psalm-var ParamsType $params */
Expand Down Expand Up @@ -201,12 +202,12 @@ private function getUniqueName(string $name, array $params): string
}

/**
* Replaces placeholders with replacements in SQL statement.
* Replaces placeholders with replacements in a SQL expression.
*
* @param string $sql SQL statement where the placeholder should be replaced.
* @param string $sql SQL expression where the placeholder should be replaced.
* @param string[] $replacements Replacements for placeholders.
*
* @return string SQL statement with the replaced placeholders.
* @return string SQL expression with replaced placeholders.
*/
private function replacePlaceholders(string $sql, array $replacements): string
{
Expand All @@ -231,9 +232,9 @@ private function replacePlaceholders(string $sql, array $replacements): string
}

/**
* Creates an instance of {@see AbstractSqlParser} for the given SQL statement.
* Creates an instance of {@see AbstractSqlParser} for the given SQL expression.
*
* @param string $sql SQL statement to be parsed.
* @param string $sql SQL expression to be parsed.
*
* @return AbstractSqlParser SQL parser instance.
*/
Expand Down

0 comments on commit 42c263e

Please sign in to comment.