From db5b3c786096f9f002578677255e36fc2a859cc7 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 30 Jul 2022 10:01:35 -0700 Subject: [PATCH] Represent query type as enum in QueryBuilder --- UPGRADE.md | 8 ++++++-- src/Query/QueryBuilder.php | 40 ++++++++++---------------------------- src/Query/QueryType.php | 16 +++++++++++++++ 3 files changed, 32 insertions(+), 32 deletions(-) create mode 100644 src/Query/QueryType.php diff --git a/UPGRADE.md b/UPGRADE.md index 6c37151262d..5ac8df9a786 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -299,8 +299,12 @@ The following `QueryBuilder` methods have been removed: The following `QueryBuilder` constants have been removed: -1. `STATE_DIRTY`, -2. `STATE_CLEAN`. +1. `SELECT`, +2. `DELETE`, +3. `UPDATE`, +4. `INSERT`, +5. `STATE_DIRTY`, +6. `STATE_CLEAN`. ## BC BREAK: Removed the `Constraint` interface. diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 0ca626b0bc0..efed3ad7e78 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -37,26 +37,6 @@ */ class QueryBuilder { - /** - * @deprecated - */ - final public const SELECT = 0; - - /** - * @deprecated - */ - final public const DELETE = 1; - - /** - * @deprecated - */ - final public const UPDATE = 2; - - /** - * @deprecated - */ - final public const INSERT = 3; - /** * The complete SQL string for this query. */ @@ -79,7 +59,7 @@ class QueryBuilder /** * The type of query this is. Can be select, update or delete. */ - private int $type = self::SELECT; + private QueryType $type = QueryType::SELECT; /** * The index of the first result to retrieve. @@ -348,10 +328,10 @@ public function getSQL(): string } $sql = match ($this->type) { - self::INSERT => $this->getSQLForInsert(), - self::DELETE => $this->getSQLForDelete(), - self::UPDATE => $this->getSQLForUpdate(), - default => $this->getSQLForSelect(), + QueryType::INSERT => $this->getSQLForInsert(), + QueryType::DELETE => $this->getSQLForDelete(), + QueryType::UPDATE => $this->getSQLForUpdate(), + QueryType::SELECT => $this->getSQLForSelect(), }; $this->sql = $sql; @@ -539,7 +519,7 @@ public function getMaxResults(): ?int */ public function select(string ...$expressions): self { - $this->type = self::SELECT; + $this->type = QueryType::SELECT; if (count($expressions) < 1) { return $this; @@ -591,7 +571,7 @@ public function distinct(): self */ public function addSelect(string $expression, string ...$expressions): self { - $this->type = self::SELECT; + $this->type = QueryType::SELECT; $this->select = array_merge($this->select, [$expression], $expressions); @@ -617,7 +597,7 @@ public function addSelect(string $expression, string ...$expressions): self */ public function delete(string $table): self { - $this->type = self::DELETE; + $this->type = QueryType::DELETE; $this->table = $table; @@ -643,7 +623,7 @@ public function delete(string $table): self */ public function update(string $table): self { - $this->type = self::UPDATE; + $this->type = QueryType::UPDATE; $this->table = $table; @@ -673,7 +653,7 @@ public function update(string $table): self */ public function insert(string $table): self { - $this->type = self::INSERT; + $this->type = QueryType::INSERT; $this->table = $table; diff --git a/src/Query/QueryType.php b/src/Query/QueryType.php new file mode 100644 index 00000000000..5544ffd8bd4 --- /dev/null +++ b/src/Query/QueryType.php @@ -0,0 +1,16 @@ +