Skip to content
This repository was archived by the owner on Aug 13, 2023. It is now read-only.

Commit 261a6d6

Browse files
committed
reformat code
1 parent 7aa7d6c commit 261a6d6

7 files changed

Lines changed: 111 additions & 114 deletions

File tree

src/QueryBuilder/Adapter/MySQL.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77
class MySQL implements Adapter
88
{
99

10-
/**
11-
* @return \PDO
12-
*/
13-
public function connection()
14-
{
15-
return null;
16-
}
17-
1810
/**
1911
* @return array
2012
*/
@@ -31,6 +23,14 @@ public function insertId()
3123
return $this->connection()->lastInsertId();
3224
}
3325

26+
/**
27+
* @return \PDO
28+
*/
29+
public function connection()
30+
{
31+
return null;
32+
}
33+
3434
/**
3535
* @return string
3636
*/

src/QueryBuilder/Instruction.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,33 @@ public function __construct(QueryBuilder $builder)
3030
$this->builder = $builder;
3131
}
3232

33+
/**
34+
* @return string
35+
*/
36+
public function __toString()
37+
{
38+
$this->attributes = [];
39+
$sql = [];
40+
41+
foreach ($this->operators() as $operator => $strict)
42+
{
43+
$data = $this->getStorage($operator);
44+
$build = $this->build($operator, $data);
45+
46+
if (!empty($build))
47+
{
48+
$sql[] = $strict . ' ' . $build;
49+
}
50+
}
51+
52+
return implode(' ', $sql);
53+
}
54+
55+
/**
56+
* @return array
57+
*/
58+
abstract protected function operators();
59+
3360
/**
3461
* @param string $name
3562
*
@@ -55,28 +82,11 @@ public function getStorage($name)
5582
}
5683

5784
/**
58-
* @param array $attributes
59-
*/
60-
protected function push(array $attributes)
61-
{
62-
$this->attributes = array_merge($this->attributes, $attributes);
63-
}
64-
65-
/**
66-
* @param $value
67-
* @param $quote
85+
* @return array
6886
*/
69-
protected function buildRAW(&$value, &$quote)
87+
protected function &defaults()
7088
{
71-
72-
if ($value instanceof RawQuery || $value instanceof self)
73-
{
74-
$this->push($value->attributes());
75-
$quote = false;
76-
77-
$value = '(' . (string)$value . ')';
78-
}
79-
89+
return [];
8090
}
8191

8292
/**
@@ -124,46 +134,36 @@ protected function build($name, $storage)
124134
}
125135

126136
/**
127-
* @return string
137+
* @param $value
138+
* @param $quote
128139
*/
129-
public function __toString()
140+
protected function buildRAW(&$value, &$quote)
130141
{
131-
$this->attributes = [];
132-
$sql = [];
133142

134-
foreach ($this->operators() as $operator => $strict)
143+
if ($value instanceof RawQuery || $value instanceof self)
135144
{
136-
$data = $this->getStorage($operator);
137-
$build = $this->build($operator, $data);
145+
$this->push($value->attributes());
146+
$quote = false;
138147

139-
if (!empty($build))
140-
{
141-
$sql[] = $strict . ' ' . $build;
142-
}
148+
$value = '(' . (string)$value . ')';
143149
}
144150

145-
return implode(' ', $sql);
146151
}
147152

148153
/**
149-
* @return array
154+
* @param array $attributes
150155
*/
151-
public function attributes()
156+
protected function push(array $attributes)
152157
{
153-
return $this->attributes;
158+
$this->attributes = array_merge($this->attributes, $attributes);
154159
}
155160

156161
/**
157162
* @return array
158163
*/
159-
protected function &defaults()
164+
public function attributes()
160165
{
161-
return [];
166+
return $this->attributes;
162167
}
163168

164-
/**
165-
* @return array
166-
*/
167-
abstract protected function operators();
168-
169169
}

src/QueryBuilder/Instruction/Insert.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class Insert extends Instruction
1919
protected function operators()
2020
{
2121
return [
22-
'from' => 'INSERT INTO',
23-
'values' => '',
22+
'from' => 'INSERT INTO',
23+
'values' => '',
2424
];
2525
}
2626

src/QueryBuilder/Operator/Classes/Join.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,6 @@ public function raw($query, array $attributes = [])
108108
return $this->select;
109109
}
110110

111-
/**
112-
* @return array
113-
*/
114-
public function getTable()
115-
{
116-
return $this->table;
117-
}
118-
119111
public function attributes()
120112
{
121113
$table = current($this->table);
@@ -143,4 +135,12 @@ public function __toString()
143135

144136
}
145137

138+
/**
139+
* @return array
140+
*/
141+
public function getTable()
142+
{
143+
return $this->table;
144+
}
145+
146146
}

src/QueryBuilder/Operator/Having.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Deimos\QueryBuilder\Operator;
44

5-
use Deimos\QueryBuilder\RawQuery;
6-
75
/**
86
* Class Having
97
*

src/QueryBuilder/Operator/Limit.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ public function limit($value)
2222
return $this;
2323
}
2424

25-
/**
26-
* @return int
27-
*/
28-
protected function storageLimit()
29-
{
30-
return $this->storageLimit;
31-
}
32-
3325
protected function buildLimit($limit)
3426
{
3527
if (method_exists($this, 'storageOffset'))
@@ -52,4 +44,12 @@ protected function buildLimit($limit)
5244
return $this->storageLimit();
5345
}
5446

47+
/**
48+
* @return int
49+
*/
50+
protected function storageLimit()
51+
{
52+
return $this->storageLimit;
53+
}
54+
5555
}

src/QueryBuilder/Operator/Where.php

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
trait Where
1414
{
1515

16+
protected $allowOperator;
1617
/**
1718
* @var array
1819
*/
1920
private $storageWhere = [];
2021

21-
protected $allowOperator;
22-
2322
/**
2423
* @param array ...$fields
2524
*
@@ -123,40 +122,24 @@ protected function buildWhereOne(...$args)
123122
return implode(' ', $list);
124123
}
125124

126-
/**
127-
* @param array $storage
128-
* @param string $toStorage
129-
*/
130-
protected function buildIf2String(array $storage, &$toStorage)
125+
protected function buildWhere($storage)
131126
{
132-
$toStorage .= '(';
133-
$lastOperator = '';
127+
/**
128+
* @var array $where
129+
*/
130+
$where = $this->buildWhereOperator($storage);
134131

135-
foreach ($storage as $key => $value)
132+
// fixme: $where = [$where];
133+
if (!is_array($where[0]))
136134
{
137-
if (is_string($value[0]))
138-
{
139-
$this->allowOperator = true;
140-
$lastOperator = $value[0];
141-
if ($key)
142-
{
143-
$toStorage .= ' ' . $lastOperator . ' ';
144-
}
145-
146-
$toStorage .= ' (' . $value[1] . ') ';
147-
}
148-
else
149-
{
150-
if ($this->allowOperator)
151-
{
152-
$toStorage .= ' ' . $lastOperator . ' ';
153-
}
154-
155-
$this->buildIf2String($value, $toStorage);
156-
}
135+
$where = [$where];
157136
}
158137

159-
$toStorage .= ')';
138+
$sql = '';
139+
$this->allowOperator = false;
140+
$this->buildIf2String($where, $sql);
141+
142+
return $sql;
160143
}
161144

162145
/**
@@ -195,24 +178,40 @@ protected function buildWhereOperator(array $args, $defaultOperator = 'AND')
195178
return $storage;
196179
}
197180

198-
protected function buildWhere($storage)
181+
/**
182+
* @param array $storage
183+
* @param string $toStorage
184+
*/
185+
protected function buildIf2String(array $storage, &$toStorage)
199186
{
200-
/**
201-
* @var array $where
202-
*/
203-
$where = $this->buildWhereOperator($storage);
187+
$toStorage .= '(';
188+
$lastOperator = '';
204189

205-
// fixme: $where = [$where];
206-
if (!is_array($where[0]))
190+
foreach ($storage as $key => $value)
207191
{
208-
$where = [$where];
209-
}
192+
if (is_string($value[0]))
193+
{
194+
$this->allowOperator = true;
195+
$lastOperator = $value[0];
196+
if ($key)
197+
{
198+
$toStorage .= ' ' . $lastOperator . ' ';
199+
}
210200

211-
$sql = '';
212-
$this->allowOperator = false;
213-
$this->buildIf2String($where, $sql);
201+
$toStorage .= ' (' . $value[1] . ') ';
202+
}
203+
else
204+
{
205+
if ($this->allowOperator)
206+
{
207+
$toStorage .= ' ' . $lastOperator . ' ';
208+
}
214209

215-
return $sql;
210+
$this->buildIf2String($value, $toStorage);
211+
}
212+
}
213+
214+
$toStorage .= ')';
216215
}
217216

218217
}

0 commit comments

Comments
 (0)