Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Drivers/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -39,27 +39,27 @@ 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";
}

#[\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
Expand Down
10 changes: 5 additions & 5 deletions src/Drivers/PgSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) <jagepard@yandex.ru>
* @author Korotkov Danila (Jagepard) <jagepard@yandex.ru>
* @license https://mozilla.org/MPL/2.0/ MPL-2.0
*/

Expand All @@ -26,7 +26,7 @@ public function groupConcat(string $fieldName, string $alias, ?string $orderBy,
#[\Override]
public function close(): string
{
return ");";
return ');';
}

#[\Override]
Expand Down Expand Up @@ -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 '';
}
}
8 changes: 4 additions & 4 deletions src/Drivers/SQLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function groupConcat(string $fieldName, string $alias, ?string $orderBy,
#[\Override]
public function close(): string
{
return ")";
return ')';
}

#[\Override]
Expand Down Expand Up @@ -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 '';
}
}
4 changes: 2 additions & 2 deletions src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Interfaces/SqlDialectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
16 changes: 8 additions & 8 deletions src/QB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions src/Traits/CrudTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -182,7 +182,7 @@ protected static function updateStmtString(array $fields): string
$stmtFields[] = "{$key}=:{$key}";
}

return implode(",", $stmtFields);
return implode(',', $stmtFields);
}

/**
Expand All @@ -202,6 +202,6 @@ protected static function createStmtString(array $fields): array
$execute[] = ":{$key}";
}

return [implode(",", $insert), implode(",", $execute)];
return [implode(',', $insert), implode(',', $execute)];
}
}
12 changes: 6 additions & 6 deletions src/Traits/SchemaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}')"
);
}
Expand All @@ -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'];
}
Expand Down
Loading