diff --git a/src/Query/CreateTable.php b/src/Query/CreateTable.php index ff0fa63..19d8472 100644 --- a/src/Query/CreateTable.php +++ b/src/Query/CreateTable.php @@ -25,10 +25,10 @@ */ class CreateTable extends Statement implements Query, IfNotExists{ - protected bool $temp = false; - protected string|null $primaryKey = null; - protected array $cols = []; - protected string|null $dir = null; + protected bool $temp = false; + protected string|null $primaryKey = null; + protected array $cols = []; + protected string|null $dir = null; public function name(string $name):static{ return $this->setName($name); @@ -42,7 +42,6 @@ public function ifNotExists():static{ return $this->setIfNotExists(); } - /** @inheritdoc */ protected function getSQL():array{ return $this->dialect->createTable($this->name, $this->cols, $this->primaryKey, $this->ifNotExists, $this->temp, $this->dir); } @@ -60,7 +59,17 @@ public function primaryKey(string $field, string|null $dir = null):static{ return $this; } - public function field(string $name, string $type, mixed $length = null, string|null $attribute = null, string|null $collation = null, bool|null $isNull = null, string|null $defaultType = null, mixed $defaultValue = null, string|null $extra = null):static{ + public function field( + string $name, + string $type, + mixed $length = null, + string|null $attribute = null, + string|null $collation = null, + bool|null $isNull = null, + string|null $defaultType = null, + mixed $defaultValue = null, + string|null $extra = null, + ):static{ if(is_scalar($defaultValue) && $defaultType === null){ $defaultType = 'USER_DEFINED'; @@ -78,39 +87,39 @@ public function enum(string $name, array $values, mixed $defaultValue = null, bo } public function tinyint(string $name, int|null $length = null, mixed $defaultValue = null, bool|null $isNull = null, string|null $attribute = null):static{ - return $this->field($name, 'TINYINT', $length, $attribute, null, $isNull, null, $defaultValue); + return $this->field(name: $name, type: 'TINYINT', length: $length, attribute: $attribute, isNull: $isNull, defaultValue: $defaultValue); } public function int(string $name, int|null $length = null, mixed $defaultValue = null, bool|null $isNull = null, string|null $attribute = null):static{ - return $this->field($name, 'INT', $length, $attribute, null, $isNull, null, $defaultValue); + return $this->field(name: $name, type: 'INT', length: $length, attribute: $attribute, isNull: $isNull, defaultValue: $defaultValue); } public function bigint(string $name, int|null $length = null, mixed $defaultValue = null, bool|null $isNull = null, string|null $attribute = null):static{ - return $this->field($name, 'BIGINT', $length, $attribute, null, $isNull, null, $defaultValue); + return $this->field(name: $name, type: 'BIGINT', length: $length, attribute: $attribute, isNull: $isNull, defaultValue: $defaultValue); } public function varchar(string $name, int $length, mixed $defaultValue = null, bool|null $isNull = null):static{ - return $this->field($name, 'VARCHAR', $length, null, null, $isNull, null, $defaultValue); + return $this->field(name: $name, type: 'VARCHAR', length: $length, isNull: $isNull, defaultValue: $defaultValue); } public function decimal(string $name, string $length, mixed $defaultValue = null, bool|null $isNull = null):static{ - return $this->field($name, 'DECIMAL', $length, null, null, $isNull, null, $defaultValue); + return $this->field(name: $name, type: 'DECIMAL', length: $length, isNull: $isNull, defaultValue: $defaultValue); } public function tinytext(string $name, mixed $defaultValue = null, bool|null $isNull = null):static{ - return $this->field($name, 'TINYTEXT', null, null, null, $isNull, null, $defaultValue); + return $this->field(name: $name, type: 'TINYTEXT', isNull: $isNull, defaultValue: $defaultValue); } public function text(string $name, mixed $defaultValue = null, bool|null $isNull = null):static{ - return $this->field($name, 'TEXT', null, null, null, $isNull, null, $defaultValue); + return $this->field(name: $name, type: 'TEXT', isNull: $isNull, defaultValue: $defaultValue); } public function mediumtext(string $name, mixed $defaultValue = null, bool|null $isNull = null):static{ - return $this->field($name, 'MEDIUMTEXT', null, null, null, $isNull, null, $defaultValue); + return $this->field(name: $name, type: 'MEDIUMTEXT', isNull: $isNull, defaultValue: $defaultValue); } public function longtext(string $name, mixed $defaultValue = null, bool|null $isNull = null):static{ - return $this->field($name, 'LONGTEXT', null, null, null, $isNull, null, $defaultValue); + return $this->field(name: $name, type: 'LONGTEXT', isNull: $isNull, defaultValue: $defaultValue); } } diff --git a/src/Query/Delete.php b/src/Query/Delete.php index 020d758..24da222 100644 --- a/src/Query/Delete.php +++ b/src/Query/Delete.php @@ -24,7 +24,7 @@ public function from(string $name):static{ return $this->setName($name); } - public function where($val1, $val2 = null, string|null $operator = null, bool|null $bind = null, string|null $join = null):static{ + public function where(mixed $val1, mixed $val2 = null, string|null $operator = null, bool|null $bind = null, string|null $join = null):static{ return $this->setWhere($val1, $val2, $operator, $bind, $join); } @@ -44,9 +44,8 @@ public function offset(int $offset):static{ return $this->setOffset($offset); } - /** @inheritdoc */ protected function getSQL():array{ - return $this->dialect->delete($this->name, $this->_getWhere()); + return $this->dialect->delete($this->name, $this->getWhere()); } } diff --git a/src/Query/Insert.php b/src/Query/Insert.php index f05e3d6..b96851f 100644 --- a/src/Query/Insert.php +++ b/src/Query/Insert.php @@ -42,7 +42,6 @@ public function values(iterable $values):static{ return $this; } - /** @inheritdoc */ protected function getSQL():array{ if(empty($this->bindValues)){ diff --git a/src/Query/Query.php b/src/Query/Query.php index 2988d47..167a2e7 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -13,17 +13,9 @@ interface Query{ - /** - * @param bool|null $multi - * - * @return string - */ public function sql(bool|null $multi = null):string; /** - * @param string|null $index - * - * @return \chillerlan\Database\Result|bool * @throws \chillerlan\Database\Query\QueryException */ public function query(string|null $index = null); diff --git a/src/Query/Select.php b/src/Query/Select.php index 5fe5069..8e35870 100644 --- a/src/Query/Select.php +++ b/src/Query/Select.php @@ -23,11 +23,11 @@ */ class Select extends Statement implements Where, Limit, BindValues, Query, CachedQuery{ - protected bool $distinct = false; - protected array $cols = []; - protected array $from = []; - protected array $orderby = []; - protected array $groupby = []; + protected bool $distinct = false; + protected array $cols = []; + protected array $from = []; + protected array $orderby = []; + protected array $groupby = []; public function where(mixed $val1, mixed $val2 = null, string|null $operator = null, bool|null $bind = null, string|null $join = null):static{ return $this->setWhere($val1, $val2, $operator, $bind, $join); @@ -53,14 +53,13 @@ public function cached(int|null $ttl = null):static{ return $this->setCached($ttl); } - /** @inheritdoc */ protected function getSQL():array{ if(empty($this->from)){ throw new QueryException('no FROM expression specified'); } - return $this->dialect->select($this->cols, $this->from, $this->_getWhere(), $this->limit, $this->offset, $this->distinct, $this->groupby, $this->orderby); + return $this->dialect->select($this->cols, $this->from, $this->getWhere(), $this->limit, $this->offset, $this->distinct, $this->groupby, $this->orderby); } public function distinct():static{ @@ -102,7 +101,7 @@ public function count():int{ throw new QueryException('no FROM expression specified'); } - $sql = $this->dialect->selectCount($this->from, $this->_getWhere(), $this->distinct, $this->groupby); + $sql = $this->dialect->selectCount($this->from, $this->getWhere(), $this->distinct, $this->groupby); $result = $this->db->prepared(implode(' ', $sql), $this->bindValues); if($result instanceof ResultInterface && $result->count() > 0){ diff --git a/src/Query/ShowCreateTable.php b/src/Query/ShowCreateTable.php index 838e8a7..cf623b2 100644 --- a/src/Query/ShowCreateTable.php +++ b/src/Query/ShowCreateTable.php @@ -17,7 +17,6 @@ public function name(string $name):static{ return $this->setName($name); } - /** @inheritdoc */ protected function getSQL():array{ return $this->dialect->showCreateTable($this->name); } diff --git a/src/Query/ShowDatabases.php b/src/Query/ShowDatabases.php index 88f6a8f..f684a77 100644 --- a/src/Query/ShowDatabases.php +++ b/src/Query/ShowDatabases.php @@ -13,7 +13,6 @@ class ShowDatabases extends Statement implements Query{ - /** @inheritdoc */ protected function getSQL():array{ return $this->dialect->showDatabases(); // @todo? WHERE } diff --git a/src/Query/ShowTables.php b/src/Query/ShowTables.php index 6d4c0cd..4af5973 100644 --- a/src/Query/ShowTables.php +++ b/src/Query/ShowTables.php @@ -33,9 +33,8 @@ public function closeBracket():static{ return $this->setCloseBracket(); } - /** @inheritdoc */ protected function getSQL():array{ - return $this->dialect->showTables($this->name, $this->pattern, $this->_getWhere()); + return $this->dialect->showTables($this->name, $this->pattern, $this->getWhere()); } public function pattern(string $pattern):static{ diff --git a/src/Query/Statement.php b/src/Query/Statement.php index 5ac061b..3042ff9 100644 --- a/src/Query/Statement.php +++ b/src/Query/Statement.php @@ -60,7 +60,6 @@ public function __construct(DriverInterface $db, Dialect $dialect, LoggerInterfa $this->logger = $logger; } - /** */ protected function setName(string $name):static{ $this->name = trim($name); @@ -71,7 +70,6 @@ protected function setName(string $name):static{ return $this; } - /** */ protected function setOnConflict(string $name, string|null $on_conflict = null, string|null $conflict_target = null):static{ $this->name = trim($name); $on_conflict = trim(strtoupper($on_conflict ?? '')); @@ -92,30 +90,24 @@ protected function setOnConflict(string $name, string|null $on_conflict = null, return $this; } - /** */ protected function setCharset(string $charset):static{ $this->charset = trim($charset); return $this; } - /** */ protected function setIfExists():static{ $this->ifExists = true; return $this; } - /** */ protected function setIfNotExists():static{ $this->ifNotExists = true; return $this; } - /** - * - */ protected function setWhere(mixed $val1, mixed $val2, string|null $operator = null, bool|null $bind = null, string|null $join = null):static{ $operator = $operator !== null ? strtoupper(trim($operator)) : '='; $bind ??= true; @@ -139,7 +131,7 @@ protected function setWhere(mixed $val1, mixed $val2, string|null $operator = nu $this->bindValues = array_merge($this->bindValues, $val2); } else{ - $where[] = $operator.'('.implode(',', array_map([$this->db, 'escape'], $val2)).')'; // @todo: quote + $where[] = $operator.'('.implode(',', array_map($this->db->escape(...), $val2)).')'; // @todo: quote } } @@ -199,7 +191,6 @@ protected function setWhere(mixed $val1, mixed $val2, string|null $operator = nu return $this; } - /** */ protected function setOpenBracket(string|null $join = null):static{ $join = strtoupper(trim($join ?? '')); @@ -212,15 +203,13 @@ protected function setOpenBracket(string|null $join = null):static{ return $this; } - /** */ protected function setCloseBracket():static{ $this->where[] = ')'; return $this; } - /** */ - protected function _getWhere():string{ + protected function getWhere():string{ $where = []; $joinArgs = array_merge($this->joinArgs, ['(', ')']); @@ -320,26 +309,22 @@ public function getBindValues():array{ return $this->bindValues; } - /** */ protected function addBindValue(int|string $key, mixed $value):void{ $this->bindValues[$key] = $value; } - /** */ protected function setLimit(int $limit):static{ $this->limit = max($limit, 0); return $this; } - /** */ protected function setOffset(int $offset):static{ $this->offset = max($offset, 0); return $this; } - /** */ protected function setCached(int|null $ttl = null):static{ $this->cached = true; diff --git a/src/Query/Truncate.php b/src/Query/Truncate.php index 61eea1c..0425fc0 100644 --- a/src/Query/Truncate.php +++ b/src/Query/Truncate.php @@ -22,7 +22,6 @@ public function table(string $name):static{ return $this->setName($name); } - /** @inheritdoc */ protected function getSQL():array{ return $this->dialect->truncate($this->name); } diff --git a/src/Query/Update.php b/src/Query/Update.php index b7203dc..253b9da 100644 --- a/src/Query/Update.php +++ b/src/Query/Update.php @@ -48,14 +48,13 @@ public function offset(int $offset):static{ return $this->setOffset($offset); } - /** @inheritdoc */ protected function getSQL():array{ if(empty($this->set)){ throw new QueryException('no fields to update specified'); } - return $this->dialect->update($this->name, $this->set, $this->_getWhere()); + return $this->dialect->update($this->name, $this->set, $this->getWhere()); } public function set(array $set, bool|null $bind = null):static{ diff --git a/src/Query/Where.php b/src/Query/Where.php index 28985e7..c86bb8d 100644 --- a/src/Query/Where.php +++ b/src/Query/Where.php @@ -18,13 +18,6 @@ */ interface Where{ - /** - * @param mixed $val1 - * @param mixed $val2 - * @param string|null $operator - * @param bool|null $bind - * @param string|null $join - */ public function where(mixed $val1, mixed $val2 = null, string|null $operator = null, bool|null $bind = null, string|null $join = null):static; public function openBracket(string|null $join = null):static;