From 6a0ac213e1a60f7c149a0d34ff8355663d065fc9 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Sat, 20 Sep 2025 18:40:24 -0400 Subject: [PATCH 1/3] Refactor query helper initialization in `UpdateQuery` and `InsertSelectQuery` to improve code clarity and remove redundant checks. --- src/InsertSelectQuery.php | 15 +++++++++------ src/UpdateQuery.php | 3 +-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/InsertSelectQuery.php b/src/InsertSelectQuery.php index b8f3270..315209d 100644 --- a/src/InsertSelectQuery.php +++ b/src/InsertSelectQuery.php @@ -60,8 +60,11 @@ public function build(DbFunctionsInterface|DbDriverInterface|null $dbDriverOrHel throw new OrmInvalidFieldsException('You must specify the fields for insert'); } + $dbDriver = null; + $dbHelper = $dbDriverOrHelper; if ($dbDriverOrHelper instanceof DbDriverInterface) { - $dbDriverOrHelper = $dbDriverOrHelper->getDbHelper(); + $dbDriver = $dbDriverOrHelper; + $dbHelper = $dbDriverOrHelper->getDbHelper(); } if (empty($this->query) && empty($this->sqlObject)) { @@ -71,13 +74,13 @@ public function build(DbFunctionsInterface|DbDriverInterface|null $dbDriverOrHel } $fieldsStr = $this->fields; - if (!is_null($dbDriverOrHelper)) { - $fieldsStr = $dbDriverOrHelper->delimiterField($fieldsStr); + if (!is_null($dbHelper)) { + $fieldsStr = $dbHelper->delimiterField($fieldsStr); } $tableStr = $this->table; - if (!is_null($dbDriverOrHelper)) { - $tableStr = $dbDriverOrHelper->delimiterTable($tableStr); + if (!is_null($dbHelper)) { + $tableStr = $dbHelper->delimiterTable($tableStr); } $sql = 'INSERT INTO ' @@ -87,7 +90,7 @@ public function build(DbFunctionsInterface|DbDriverInterface|null $dbDriverOrHel if (!is_null($this->sqlObject)) { $fromObj = $this->sqlObject; } else { - $fromObj = $this->query->build(); + $fromObj = $this->query->build($dbDriver); } return new SqlObject($sql . $fromObj->getSql(), $fromObj->getParameters()); diff --git a/src/UpdateQuery.php b/src/UpdateQuery.php index d68172f..6489f03 100644 --- a/src/UpdateQuery.php +++ b/src/UpdateQuery.php @@ -70,11 +70,10 @@ public function setLiteral(string $field, mixed $value): UpdateQuery protected function getJoinTables(DbFunctionsInterface|DbDriverInterface $dbDriverOrHelper = null): array { $dbDriver = null; + $dbHelper = $dbDriverOrHelper; if ($dbDriverOrHelper instanceof DbDriverInterface) { $dbDriver = $dbDriverOrHelper; $dbHelper = $dbDriverOrHelper->getDbHelper(); - } else { - $dbHelper = $dbDriverOrHelper; } if (is_null($dbHelper)) { From 7fa3eec2b916e0e24b85538982cf52699fd134e3 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Sun, 21 Sep 2025 17:05:11 -0400 Subject: [PATCH 2/3] Minor change --- src/UpdateQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UpdateQuery.php b/src/UpdateQuery.php index 6489f03..5b072ef 100644 --- a/src/UpdateQuery.php +++ b/src/UpdateQuery.php @@ -58,7 +58,7 @@ public function set(string $field, int|float|bool|string|LiteralInterface|null $ * Set a field with a literal value that will be used directly in the SQL query * * @param string $field - * @param string $value + * @param mixed $value * @return $this */ public function setLiteral(string $field, mixed $value): UpdateQuery From f94134a019997e9f3e6ff94b8d188e84ed9be198 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Sun, 21 Sep 2025 17:21:01 -0400 Subject: [PATCH 3/3] Minor change --- src/Literal/HexUuidLiteral.php | 6 +++--- src/Literal/MySqlUuidLiteral.php | 2 +- src/Literal/PostgresUuidLiteral.php | 2 +- src/Literal/SqlServerUuidLiteral.php | 2 +- src/Literal/SqliteUuidLiteral.php | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Literal/HexUuidLiteral.php b/src/Literal/HexUuidLiteral.php index cc6c6dd..5ca21da 100644 --- a/src/Literal/HexUuidLiteral.php +++ b/src/Literal/HexUuidLiteral.php @@ -11,7 +11,7 @@ class HexUuidLiteral extends Literal protected string $formattedUuid; - public function __construct(HexUuidLiteral|string $value) + public function __construct(Literal|string $value) { parent::__construct($this->binaryString($value)); } @@ -39,7 +39,7 @@ public static function create(mixed $value): mixed /** * @throws InvalidArgumentException */ - public function binaryString(HexUuidLiteral|string $value): string + public function binaryString(Literal|string $value): string { if ($value instanceof HexUuidLiteral) { $value = $value->formattedUuid; @@ -66,7 +66,7 @@ public static function getUuidFromLiteral(HexUuidLiteral $literal): string /** * @throws InvalidArgumentException */ - public static function getFormattedUuid(HexUuidLiteral|string|null $item, bool $throwErrorIfInvalid = true, $default = null): ?string + public static function getFormattedUuid(Literal|string|null $item, bool $throwErrorIfInvalid = true, $default = null): ?string { if ($item instanceof Literal) { $item = $item->__toString(); diff --git a/src/Literal/MySqlUuidLiteral.php b/src/Literal/MySqlUuidLiteral.php index 18d23e3..dec9a16 100644 --- a/src/Literal/MySqlUuidLiteral.php +++ b/src/Literal/MySqlUuidLiteral.php @@ -4,7 +4,7 @@ class MySqlUuidLiteral extends HexUuidLiteral { - public function __construct(HexUuidLiteral|string $value) + public function __construct(Literal|string $value) { if ($value instanceof HexUuidLiteral) { $value = $value->formattedUuid; diff --git a/src/Literal/PostgresUuidLiteral.php b/src/Literal/PostgresUuidLiteral.php index b6bd1cc..6d0ddef 100644 --- a/src/Literal/PostgresUuidLiteral.php +++ b/src/Literal/PostgresUuidLiteral.php @@ -4,7 +4,7 @@ class PostgresUuidLiteral extends HexUuidLiteral { - public function __construct(HexUuidLiteral|string $value) + public function __construct(Literal|string $value) { if ($value instanceof HexUuidLiteral) { $value = $value->formattedUuid; diff --git a/src/Literal/SqlServerUuidLiteral.php b/src/Literal/SqlServerUuidLiteral.php index fa6437c..fc0e86f 100644 --- a/src/Literal/SqlServerUuidLiteral.php +++ b/src/Literal/SqlServerUuidLiteral.php @@ -4,7 +4,7 @@ class SqlServerUuidLiteral extends HexUuidLiteral { - public function __construct(HexUuidLiteral|string $value) + public function __construct(Literal|string $value) { if ($value instanceof HexUuidLiteral) { $value = $value->formattedUuid; diff --git a/src/Literal/SqliteUuidLiteral.php b/src/Literal/SqliteUuidLiteral.php index d77b81c..b6098a0 100644 --- a/src/Literal/SqliteUuidLiteral.php +++ b/src/Literal/SqliteUuidLiteral.php @@ -4,7 +4,7 @@ class SqliteUuidLiteral extends HexUuidLiteral { - public function __construct(HexUuidLiteral|string $value) + public function __construct(Literal|string $value) { if ($value instanceof HexUuidLiteral) { $value = $value->formattedUuid;