From 79527decacfc10930d0d71d6106653f3a87e8717 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov <rrr-r@ya.ru> Date: Fri, 28 Jul 2023 15:52:21 +0700 Subject: [PATCH] Refactor JsonExpressionBuilder.php (#301) --- CHANGELOG.md | 1 + src/Builder/JsonExpressionBuilder.php | 14 +++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29e3932ea..e85fe6fda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 1.1.1 under development +- Enh #301: Refactor `JsonExpressionBuilder` (@Tigrov) - Enh #300: Refactor `ArrayExpressionBuilder` (@Tigrov) ## 1.1.0 July 24, 2023 diff --git a/src/Builder/JsonExpressionBuilder.php b/src/Builder/JsonExpressionBuilder.php index f8562eebb..e86fda354 100644 --- a/src/Builder/JsonExpressionBuilder.php +++ b/src/Builder/JsonExpressionBuilder.php @@ -29,7 +29,7 @@ public function __construct(private QueryBuilderInterface $queryBuilder) /** * The Method builds the raw SQL from the $expression that won't be additionally escaped or quoted. * - * @param ExpressionInterface $expression The expression to build. + * @param JsonExpression $expression The expression to build. * @param array $params The binding parameters. * * @throws Exception @@ -39,19 +39,15 @@ public function __construct(private QueryBuilderInterface $queryBuilder) * @throws NotSupportedException * * @return string The raw SQL that won't be additionally escaped or quoted. - * - * @psalm-param JsonExpression $expression */ public function build(ExpressionInterface $expression, array &$params = []): string { - /** - * @psalm-var array|mixed|QueryInterface $value - */ + /** @psalm-var mixed $value */ $value = $expression->getValue(); if ($value instanceof QueryInterface) { [$sql, $params] = $this->queryBuilder->build($value, $params); - return "($sql)" . $this->getTypecast($expression); + return "($sql)" . $this->getTypeHint($expression); } if ($value instanceof ArrayExpression) { @@ -60,13 +56,13 @@ public function build(ExpressionInterface $expression, array &$params = []): str $placeholder = $this->queryBuilder->bindParam(Json::encode($value), $params); } - return $placeholder . $this->getTypecast($expression); + return $placeholder . $this->getTypeHint($expression); } /** * @return string The typecast expression based on {@see JsonExpression::getType()}. */ - protected function getTypecast(JsonExpression $expression): string + private function getTypeHint(JsonExpression $expression): string { $type = $expression->getType();