diff --git a/src/Drivers/MySQL.php b/src/Drivers/MySQL.php index d1776c6..934eea4 100755 --- a/src/Drivers/MySQL.php +++ b/src/Drivers/MySQL.php @@ -25,11 +25,11 @@ public function groupConcat(string $fieldName, string $alias, ?string $orderBy, #[\Override] public function close(): string { - return ") ENGINE = InnoDB"; + return ') ENGINE = InnoDB'; } #[\Override] - public function integer(string $field, string $default = "", bool $autoincrement = false, string $null = "NOT NULL"): string + public function integer(string $field, string $default = '', bool $autoincrement = false, string $null = 'NOT NULL'): string { if ($autoincrement) { return "`$field` INT $null AUTO_INCREMENT $default"; @@ -39,13 +39,13 @@ public function integer(string $field, string $default = "", bool $autoincrement } #[\Override] - public function string(string $field, string $default = "", string $null = "NOT NULL"): string + public function string(string $field, string $default = '', string $null = 'NOT NULL'): string { return ", `$field` VARCHAR(255) $null $default"; } #[\Override] - public function text(string $field, string $null = "NOT NULL"): string + public function text(string $field, string $null = 'NOT NULL'): string { return ", `$field` text $null"; } @@ -53,13 +53,13 @@ public function text(string $field, string $null = "NOT NULL"): string #[\Override] public function createdAt(): string { - return ", `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP"; + return ', `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP'; } #[\Override] public function updatedAt(): string { - return ", `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"; + return ', `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'; } public function primaryKey(string $field): string diff --git a/src/Drivers/PgSQL.php b/src/Drivers/PgSQL.php index 7e8e849..737d6e1 100755 --- a/src/Drivers/PgSQL.php +++ b/src/Drivers/PgSQL.php @@ -5,7 +5,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. * - * @author Korotkov Danila (JageDord) + * @author Korotkov Danila (Jagepard) * @license https://mozilla.org/MPL/2.0/ MPL-2.0 */ @@ -26,7 +26,7 @@ public function groupConcat(string $fieldName, string $alias, ?string $orderBy, #[\Override] public function close(): string { - return ");"; + return ');'; } #[\Override] @@ -54,18 +54,18 @@ public function text(string $field, string $null = "NOT NULL"): string #[\Override] public function createdAt(): string { - return ", created_at TIMESTAMP without time zone"; + return ', created_at TIMESTAMP without time zone'; } #[\Override] public function updatedAt(): string { - return ", updated_at TIMESTAMP without time zone"; + return ', updated_at TIMESTAMP without time zone'; } #[\Override] public function primaryKey(string $field): string { - return ""; + return ''; } } diff --git a/src/Drivers/SQLite.php b/src/Drivers/SQLite.php index f993295..a4e955f 100755 --- a/src/Drivers/SQLite.php +++ b/src/Drivers/SQLite.php @@ -25,7 +25,7 @@ public function groupConcat(string $fieldName, string $alias, ?string $orderBy, #[\Override] public function close(): string { - return ")"; + return ')'; } #[\Override] @@ -53,18 +53,18 @@ public function text(string $field, string $null = "NOT NULL"): string #[\Override] public function createdAt(): string { - return ", created_at TEXT DEFAULT CURRENT_TIMESTAMP"; + return ', created_at TEXT DEFAULT CURRENT_TIMESTAMP'; } #[\Override] public function updatedAt(): string { - return ", updated_at TEXT DEFAULT CURRENT_TIMESTAMP"; + return ', updated_at TEXT DEFAULT CURRENT_TIMESTAMP'; } #[\Override] public function primaryKey(string $field): string { - return ""; + return ''; } } diff --git a/src/Entity.php b/src/Entity.php index a6db4d6..d393a8e 100755 --- a/src/Entity.php +++ b/src/Entity.php @@ -36,11 +36,11 @@ public function __call(string $method, array $parameters = []): mixed */ protected static function callMethod(string $method, array $parameters): mixed { - $className = str_replace("Entity", "Model", get_called_class()); + $className = str_replace('Entity', 'Model', get_called_class()); // If there is no Model, then call the Repository if (!class_exists($className)) { - $className = str_replace("Entity", "Repository", get_called_class() . "Repository"); + $className = str_replace('Entity', 'Repository', get_called_class() . 'Repository'); } // If there is no Repository, then call the parent Repository diff --git a/src/Interfaces/SqlDialectInterface.php b/src/Interfaces/SqlDialectInterface.php index 4dbb486..c005894 100644 --- a/src/Interfaces/SqlDialectInterface.php +++ b/src/Interfaces/SqlDialectInterface.php @@ -15,9 +15,9 @@ interface SqlDialectInterface { public function groupConcat(string $fieldName, string $alias, ?string $orderBy, bool $distinct = true): string; public function close(): string; - public function integer(string $field, string $default = "", bool $autoincrement = false, string $null = "NOT NULL"): string; - public function string(string $field, string $default = "", string $null = "NOT NULL"): string; - public function text(string $field, string $null = "NOT NULL"): string; + public function integer(string $field, string $default = '', bool $autoincrement = false, string $null = 'NOT NULL'): string; + public function string(string $field, string $default = '', string $null = 'NOT NULL'): string; + public function text(string $field, string $null = 'NOT NULL'): string; public function createdAt(): string; public function updatedAt(): string; public function primaryKey(string $field): string; diff --git a/src/Model.php b/src/Model.php index 4727f66..3e0875f 100755 --- a/src/Model.php +++ b/src/Model.php @@ -36,7 +36,7 @@ public function __construct(?string $table = null) */ public function __call(string $method, array $parameters = []): mixed { - $className = str_replace("Model", "Repository", get_called_class()) . "Repository"; + $className = str_replace('Model', 'Repository', get_called_class()) . 'Repository'; // If there is no Repository, then call the parent Repository if (!class_exists($className)) { diff --git a/src/QB.php b/src/QB.php index 3d96383..95951f0 100755 --- a/src/QB.php +++ b/src/QB.php @@ -32,13 +32,13 @@ class QB */ public function __construct($connection = null) { - $connection = $connection ?? Rudra::get('connection') ?? throw new LogicException("connection is not installed"); + $connection = $connection ?? Rudra::get('connection') ?? throw new LogicException('connection is not installed'); - if ($connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === "mysql") { + if ($connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'mysql') { $this->driver = new MySQL; - } elseif ($connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === "pgsql") { + } elseif ($connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'pgsql') { $this->driver = new PgSQL; - } elseif ($connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === "sqlite") { + } elseif ($connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'sqlite') { $this->driver = new SQLite; } } @@ -127,7 +127,7 @@ public function groupBy(string $param): self return $this; } - public function join(string $param, string $type = "LEFT"): self + public function join(string $param, string $type = 'LEFT'): self { $this->query .= "$type JOIN $param "; return $this; @@ -159,19 +159,19 @@ public function close(): self return $this; } - public function integer(string $field, string $default = "", bool $autoincrement = false, string $null = "NOT NULL"): self + public function integer(string $field, string $default = '', bool $autoincrement = false, string $null = 'NOT NULL'): self { $this->query .= $this->driver->integer($field, $default, $autoincrement, $null); return $this; } - public function string(string $field, string $default = "", string $null = "NOT NULL"): self + public function string(string $field, string $default = '', string $null = 'NOT NULL'): self { $this->query .= $this->driver->string($field, $default, $null); return $this; } - public function text(string $field, string $null = "NOT NULL"): self + public function text(string $field, string $null = 'NOT NULL'): self { $this->query .= $this->driver->text($field, $null); return $this; diff --git a/src/Schema.php b/src/Schema.php index e20a0c4..b19b9a0 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -37,7 +37,7 @@ public static function create(string $table, callable $callback): self public static function hasTable(string $table): bool { try { - Rudra::get("connection")->query("SELECT 1 FROM `$table` LIMIT 1"); + Rudra::get('connection')->query("SELECT 1 FROM `$table` LIMIT 1"); return true; } catch (\PDOException $e) { return false; @@ -50,7 +50,7 @@ public static function hasTable(string $table): bool */ public function execute(): bool { - $connection = Rudra::get("connection"); + $connection = Rudra::get('connection'); if (isset($this->table) && self::hasTable($this->table)) { throw new \RuntimeException("Table '{$this->table}' already exists in DB"); diff --git a/src/Traits/CrudTrait.php b/src/Traits/CrudTrait.php index bd7066d..aa9c5e5 100644 --- a/src/Traits/CrudTrait.php +++ b/src/Traits/CrudTrait.php @@ -23,7 +23,7 @@ public function getAllPerPage(Pagination $pagination, ?string $fields = null): a $this->qb() ->select($fields) ->from($this->table) - ->orderBy("id DESC") + ->orderBy('id DESC') ->limit($pagination->getPerPage()) ->offset($pagination->getOffset()) ->get() @@ -171,7 +171,7 @@ public function delete(int|string $id): void /** * Generates a string of fields and placeholders for an SQL UPDATE statement. - * The method takes an array of fields and constructs a comma-separated list of "key=:key" pairs. + * The method takes an array of fields and constructs a comma-separated list of 'key=:key' pairs. * This string can be directly used in the SET clause of an SQL UPDATE query. */ protected static function updateStmtString(array $fields): string @@ -182,7 +182,7 @@ protected static function updateStmtString(array $fields): string $stmtFields[] = "{$key}=:{$key}"; } - return implode(",", $stmtFields); + return implode(',', $stmtFields); } /** @@ -202,6 +202,6 @@ protected static function createStmtString(array $fields): array $execute[] = ":{$key}"; } - return [implode(",", $insert), implode(",", $execute)]; + return [implode(',', $insert), implode(',', $execute)]; } } diff --git a/src/Traits/SchemaTrait.php b/src/Traits/SchemaTrait.php index 38f36e5..332d05b 100644 --- a/src/Traits/SchemaTrait.php +++ b/src/Traits/SchemaTrait.php @@ -24,14 +24,14 @@ public function getColumns(): array { $table = $this->table; - if ($this->connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === "mysql") { + if ($this->connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'mysql') { $query = $this->connection->query("SHOW COLUMNS FROM {$table}"); - } elseif ($this->connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === "pgsql") { + } elseif ($this->connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'pgsql') { $query = $this->connection->query("SELECT column_name, data_type FROM information_schema.columns WHERE table_name = '{$table}'" ); - } elseif ($this->connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === "sqlite") { + } elseif ($this->connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'sqlite') { $query = $this->connection->query("PRAGMA table_info('{$table}')" ); } @@ -54,15 +54,15 @@ public function getFields(?string $fields = null): array // Initialize as an empty array — protection against null $fieldList = []; - if ($this->connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === "mysql") { + if ($this->connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'mysql') { foreach ($this->getColumns() as $column) { $fieldList[] = $column['Field']; } - } elseif ($this->connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === "pgsql") { + } elseif ($this->connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'pgsql') { foreach ($this->getColumns() as $column) { $fieldList[] = $column['column_name']; } - } elseif ($this->connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === "sqlite") { + } elseif ($this->connection->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'sqlite') { foreach ($this->getColumns() as $column) { $fieldList[] = $column['name']; }