Skip to content

Commit f8fbc2f

Browse files
committed
refactor: improve string formatting and remove unnecessary backticks in query classes
1 parent 25e676e commit f8fbc2f

File tree

7 files changed

+10
-16
lines changed

7 files changed

+10
-16
lines changed

src/System/Database/MyModel/Model.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function setter(string $key, $value): self
180180
public function getter(string $key, $default = null)
181181
{
182182
if (array_key_exists($key, $this->stash)) {
183-
throw new \Exception("Cant read this colum {$key}");
183+
throw new \Exception("Cant read this column `{$key}`.");
184184
}
185185

186186
return $this->first()[$key] ?? $default;
@@ -413,7 +413,7 @@ public function isClean(?string $column = null): bool
413413
foreach (array_keys($this->columns) as $key) {
414414
if (!array_key_exists($column, $this->columns[$key])
415415
|| !array_key_exists($column, $this->fresh[$key])) {
416-
throw new \Exception("Column {$column} is not in table {$this->table_name}");
416+
throw new \Exception("Column {$column} is not in table `{$this->table_name}`.");
417417
}
418418

419419
if (false === ($this->columns[$key][$column] === $this->fresh[$key][$column])) {
@@ -550,7 +550,7 @@ public function order(string $column_name, int $order_using = MyQuery::ORDER_ASC
550550
{
551551
$order = 0 === $order_using ? 'ASC' : 'DESC';
552552
$belong_to ??= $this->table_name;
553-
$this->sort_order = "ORDER BY $belong_to.$column_name $order";
553+
$this->sort_order = "ORDER BY {$belong_to}.{$column_name} {$order}";
554554

555555
return $this;
556556
}

src/System/Database/MyQuery/InnerQuery.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function isSubQuery(): bool
1717

1818
public function getAlias(): string
1919
{
20-
return "{$this->table}";
20+
return $this->table;
2121
}
2222

2323
/** @return Bind[] */

src/System/Database/MyQuery/Query.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected function splitGrupsFilters(array $group_filters): string
177177
protected function splitFilters(array $filters): string
178178
{
179179
$query = [];
180-
$table_name = null === $this->_sub_query ? "{$this->_table}" : $this->_sub_query->getAlias();
180+
$table_name = null === $this->_sub_query ? $this->_table : $this->_sub_query->getAlias();
181181
foreach ($filters['filters'] as $fieldName => $fieldValue) {
182182
$value = $fieldValue['value'];
183183
$comparation = $fieldValue['comparation'];

src/System/Database/MyQuery/Select.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ public function __construct($table_name, array $columns_name, MyPDO $PDO, ?array
3434
$this->_binds = $table_name->getBind();
3535
}
3636

37-
// defaul query
38-
if (count($this->_column) > 1) {
39-
$this->_column = array_map(fn ($e) => "$e", $this->_column);
40-
}
41-
4237
$column = implode(', ', $columns_name);
4338
$this->_query = $options['query'] ?? "SELECT {$column} FROM { $this->_sub_query}";
4439
}
@@ -49,7 +44,7 @@ public function __toString()
4944
}
5045

5146
/**
52-
* Instance of Select::class.
47+
* Instance of `Select::class`.
5348
*
5449
* @param string $table_name Table name
5550
* @param string[] $column_name Selected column

src/System/Database/MyQuery/Traits/ConditionTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function where(string $where_condition, array $binder = [])
7575
*/
7676
public function between(string $column_name, $value_1, $value_2)
7777
{
78-
$table_name = null === $this->_sub_query ? "{$this->_table}" : $this->_sub_query->getAlias();
78+
$table_name = null === $this->_sub_query ? $this->_table : $this->_sub_query->getAlias();
7979

8080
$this->where(
8181
"({$table_name}.{$column_name} BETWEEN :b_start AND :b_end)",

src/System/Database/MyQuery/Update.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function builder(): string
6262
$setter = [];
6363
foreach ($this->_binds as $bind) {
6464
if ($bind->hasColumName()) {
65-
$setter[] = '' . $bind->getColumnName() . ' = ' . $bind->getBind();
65+
$setter[] = $bind->getColumnName() . ' = ' . $bind->getBind();
6666
}
6767
}
6868

src/System/Database/MySchema/Table/Create.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private function getPrimarykey(): array
126126
return [''];
127127
}
128128

129-
$primaryKeys = array_map(fn ($primaryKey) => "{$primaryKey}", $this->primaryKeys);
129+
$primaryKeys = array_map(fn ($primaryKey) => $primaryKey, $this->primaryKeys);
130130
$primaryKeys = implode(', ', $primaryKeys);
131131

132132
return ["PRIMARY KEY ({$primaryKeys})"];
@@ -139,8 +139,7 @@ private function getUnique(): array
139139
return [''];
140140
}
141141

142-
$uniques = array_map(fn ($uniques) => "{$uniques}", $this->uniques);
143-
$uniques = implode(', ', $uniques);
142+
$uniques = implode(', ', $this->uniques);
144143

145144
return ["UNIQUE ({$uniques})"];
146145
}

0 commit comments

Comments
 (0)