Skip to content

Commit 522bfcb

Browse files
committed
reset
1 parent 04d014b commit 522bfcb

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
153153

154154
### Security
155155
- Nothing
156+
157+
## [1.4.1] - 2020-02-04
158+
159+
### Added
160+
- Nothing
161+
162+
### Deprecated
163+
- Nothing
164+
165+
### Fixed
166+
- Reset
167+
168+
### Removed
169+
- Nothing
170+
171+
### Security
172+
- Nothing

src/QueryMaker.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace midorikocak\querymaker;
66

7-
use Exception;
87
use InvalidArgumentException;
98

109
use function array_keys;
@@ -24,6 +23,11 @@ class QueryMaker implements QueryInterface
2423
private string $orderBy;
2524

2625
public function __construct()
26+
{
27+
$this->reset();
28+
}
29+
30+
private function reset(): void
2731
{
2832
$this->query = '';
2933
$this->statement = '';
@@ -35,8 +39,7 @@ public function __construct()
3539

3640
public function select($table, array $columns = ['*']): QueryInterface
3741
{
38-
$this->checkInitialized();
39-
42+
$this->reset();
4043
$columnsText = implode(', ', $columns);
4144
$this->statement = 'SELECT ' . $columnsText . ' FROM ' . $table;
4245
$this->query = 'SELECT ' . $columnsText . ' FROM ' . $table;
@@ -45,8 +48,7 @@ public function select($table, array $columns = ['*']): QueryInterface
4548

4649
public function update($table, array $values): QueryInterface
4750
{
48-
$this->checkInitialized();
49-
51+
$this->reset();
5052
$this->statement = 'UPDATE ' . $table . ' SET ';
5153
$this->query = 'UPDATE ' . $table . ' SET ';
5254
$this->prepareParams($values, ', ');
@@ -55,7 +57,7 @@ public function update($table, array $values): QueryInterface
5557

5658
public function insert($table, array $values): QueryInterface
5759
{
58-
$this->checkInitialized();
60+
$this->reset();
5961
$fields = implode(', ', array_keys($values));
6062
$params = implode(', ', array_map(fn($key) => ':' . $key, array_keys($values)));
6163
$queryValues = implode(', ', array_map(fn($value) => "'$value'", array_values($values)));
@@ -69,7 +71,7 @@ public function insert($table, array $values): QueryInterface
6971

7072
public function delete($table): QueryInterface
7173
{
72-
$this->checkInitialized();
74+
$this->reset();
7375
$this->statement = 'DELETE FROM ' . $table;
7476
$this->query = 'DELETE FROM ' . $table;
7577
return $this;
@@ -189,11 +191,4 @@ private function checkOperator(string $operator): void
189191
throw new InvalidArgumentException('Invalid Operator');
190192
}
191193
}
192-
193-
private function checkInitialized()
194-
{
195-
if ($this->statement !== '' && $this->query !== '') {
196-
throw new Exception('Invalid Query Order');
197-
}
198-
}
199194
}

0 commit comments

Comments
 (0)