@@ -21,7 +21,7 @@ |
||
21 | 21 | * @return string |
22 | 22 | */ |
23 | 23 | protected function buildOffset($query) { |
24 | - if($this->offset !== null) { |
|
24 | + if ($this->offset !== null) { |
|
25 | 25 | $query .= "OFFSET\n\t{$this->offset}\n"; |
26 | 26 | } |
27 | 27 | return $query; |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @return $this |
30 | 30 | */ |
31 | 31 | public function from($alias, $table = null) { |
32 | - if($table !== null) { |
|
32 | + if ($table !== null) { |
|
33 | 33 | $this->aliases[] = $alias; |
34 | 34 | } |
35 | 35 | $this->addTable($alias, $table); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | public function __toString() { |
44 | 44 | $query = "DELETE "; |
45 | 45 | $query .= join(', ', $this->aliases); |
46 | - $query = trim($query) . " FROM\n"; |
|
46 | + $query = trim($query)." FROM\n"; |
|
47 | 47 | $query = $this->buildTables($query); |
48 | 48 | $query = $this->buildJoins($query); |
49 | 49 | $query = $this->buildWhereConditions($query); |
@@ -8,8 +8,8 @@ |
||
8 | 8 | * @return array |
9 | 9 | */ |
10 | 10 | public static function convertValues(array $row, array $columnDefinitions) { |
11 | - foreach($row as $key => &$value) { |
|
12 | - if($value !== null) { |
|
11 | + foreach ($row as $key => &$value) { |
|
12 | + if ($value !== null) { |
|
13 | 13 | $value = self::convertValue($value, $columnDefinitions[$key]); |
14 | 14 | } |
15 | 15 | } |
@@ -27,8 +27,8 @@ |
||
27 | 27 | * @return DBExprFilter |
28 | 28 | */ |
29 | 29 | public function __invoke($expression, $keyPath, $validator = null) { |
30 | - return new DBExprFilter($expression, $this->map, $keyPath, $validator, function ($result, array $data) { |
|
31 | - if(!$result) { |
|
30 | + return new DBExprFilter($expression, $this->map, $keyPath, $validator, function($result, array $data) { |
|
31 | + if (!$result) { |
|
32 | 32 | throw new RequiredValueNotFoundException(sprintf("Required value %s not found", $data['key'])); |
33 | 33 | } |
34 | 34 | }); |
@@ -28,10 +28,10 @@ |
||
28 | 28 | */ |
29 | 29 | protected function buildLimit($query, $offset = null) { |
30 | 30 | $limit = $this->limit; |
31 | - if($limit === null && $offset !== null) { |
|
31 | + if ($limit === null && $offset !== null) { |
|
32 | 32 | $limit = '18446744073709551615'; |
33 | 33 | } |
34 | - if($limit !== null) { |
|
34 | + if ($limit !== null) { |
|
35 | 35 | $query .= "LIMIT\n\t{$limit}\n"; |
36 | 36 | } |
37 | 37 | return $query; |
@@ -11,16 +11,16 @@ |
||
11 | 11 | */ |
12 | 12 | public function __construct($spec, $sortFieldsSpec) { |
13 | 13 | $expressions = []; |
14 | - foreach($spec as $specReference => $dbExpr) { |
|
15 | - if(is_int($specReference)) { |
|
14 | + foreach ($spec as $specReference => $dbExpr) { |
|
15 | + if (is_int($specReference)) { |
|
16 | 16 | $specReference = $dbExpr; |
17 | 17 | } |
18 | 18 | $expressions[$specReference] = $dbExpr; |
19 | 19 | } |
20 | - foreach($sortFieldsSpec as $sortFieldSpec) { |
|
21 | - if(array_key_exists(0, $sortFieldSpec) && array_key_exists($sortFieldSpec[0], $expressions)) { |
|
20 | + foreach ($sortFieldsSpec as $sortFieldSpec) { |
|
21 | + if (array_key_exists(0, $sortFieldSpec) && array_key_exists($sortFieldSpec[0], $expressions)) { |
|
22 | 22 | $direction = 'ASC'; |
23 | - if(array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') { |
|
23 | + if (array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') { |
|
24 | 24 | $direction = 'DESC'; |
25 | 25 | } |
26 | 26 | $this->fields[] = [ |
@@ -13,36 +13,36 @@ |
||
13 | 13 | * @return string |
14 | 14 | */ |
15 | 15 | protected function buildTableName($alias, $name) { |
16 | - if(is_object($name) && !($name instanceof VirtualTable)) { |
|
16 | + if (is_object($name) && !($name instanceof VirtualTable)) { |
|
17 | 17 | $name = (string) $name; |
18 | 18 | $lines = explode("\n", $name); |
19 | - foreach($lines as &$line) { |
|
19 | + foreach ($lines as &$line) { |
|
20 | 20 | $line = "\t{$line}"; |
21 | 21 | } |
22 | 22 | $name = join("\n", $lines); |
23 | - $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
|
23 | + $name = '('.trim(rtrim(trim($name), ';')).')'; |
|
24 | 24 | } |
25 | - if(is_array($name)) { |
|
25 | + if (is_array($name)) { |
|
26 | 26 | $parts = []; |
27 | - foreach($name as $index => $bucket) { |
|
28 | - if(ctype_digit((string) $index) && is_scalar($bucket)) { |
|
27 | + foreach ($name as $index => $bucket) { |
|
28 | + if (ctype_digit((string) $index) && is_scalar($bucket)) { |
|
29 | 29 | $parts[] = "SELECT {$this->db()->quote($bucket)} AS {$this->db()->quoteField('value')}"; |
30 | 30 | } else { |
31 | 31 | $values = []; |
32 | - foreach($bucket as $field => $value) { |
|
32 | + foreach ($bucket as $field => $value) { |
|
33 | 33 | $values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field)); |
34 | 34 | } |
35 | 35 | $parts[] = sprintf("SELECT %s", join(', ', $values)); |
36 | 36 | } |
37 | 37 | } |
38 | - $name = '(' . join("\n\tUNION\n\t", $parts) . ')'; |
|
38 | + $name = '('.join("\n\tUNION\n\t", $parts).')'; |
|
39 | 39 | } |
40 | - if($this->db()->getVirtualTables()->has($name)) { |
|
40 | + if ($this->db()->getVirtualTables()->has($name)) { |
|
41 | 41 | $select = (string) $this->db()->getVirtualTables()->get($name); |
42 | 42 | $name = sprintf('(%s)', join("\n\t", explode("\n", trim($select)))); |
43 | 43 | } |
44 | 44 | $name = $this->aliasReplacer()->replace($name); |
45 | - if($alias !== null) { |
|
45 | + if ($alias !== null) { |
|
46 | 46 | return sprintf("%s %s", $name, $alias); |
47 | 47 | } |
48 | 48 | return $name; |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | * @return $this |
16 | 16 | */ |
17 | 17 | public function orderBy($expression, $direction = 'asc') { |
18 | - if($expression instanceof OrderBySpecification) { |
|
19 | - foreach($expression->getFields() as $field) { |
|
18 | + if ($expression instanceof OrderBySpecification) { |
|
19 | + foreach ($expression->getFields() as $field) { |
|
20 | 20 | $this->addOrder($field[0], $field[1]); |
21 | 21 | } |
22 | 22 | return $this; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function orderByValues($fieldName, array $values) { |
34 | 34 | $expr = []; |
35 | - foreach(array_values($values) as $idx => $value) { |
|
35 | + foreach (array_values($values) as $idx => $value) { |
|
36 | 36 | $expr[] = $this->db()->quoteExpression("WHEN ? THEN ?", [$value, $idx]); |
37 | 37 | } |
38 | 38 | $this->orderBy[] = [sprintf("CASE %s\n\t\t%s\n\tEND", $this->db()->quoteField($fieldName), join("\n\t\t", $expr)), 'ASC']; |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | * @return string |
45 | 45 | */ |
46 | 46 | protected function buildOrder($query) { |
47 | - if(!count($this->orderBy)) { |
|
47 | + if (!count($this->orderBy)) { |
|
48 | 48 | return $query; |
49 | 49 | } |
50 | 50 | $query .= "ORDER BY\n"; |
51 | 51 | $arr = []; |
52 | - foreach($this->orderBy as $order) { |
|
52 | + foreach ($this->orderBy as $order) { |
|
53 | 53 | list($expression, $direction) = $order; |
54 | 54 | $arr[] = sprintf("\t%s %s", $expression, strtoupper($direction)); |
55 | 55 | } |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | */ |
63 | 63 | private function addOrder($expression, $direction) { |
64 | 64 | $direction = $this->fixDirection($direction); |
65 | - if(is_array($expression)) { |
|
66 | - if(!count($expression)) { |
|
65 | + if (is_array($expression)) { |
|
66 | + if (!count($expression)) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | $arguments = [ |
@@ -47,15 +47,15 @@ |
||
47 | 47 | */ |
48 | 48 | protected function buildJoins($query) { |
49 | 49 | $arr = []; |
50 | - foreach($this->joinTables as $table) { |
|
50 | + foreach ($this->joinTables as $table) { |
|
51 | 51 | $join = $table['type']." JOIN\n"; |
52 | - $join .= "\t" . $this->buildTableName($table['alias'], $table['name']); |
|
53 | - if($table['expression']) { |
|
54 | - $join .= " ON " . $this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
52 | + $join .= "\t".$this->buildTableName($table['alias'], $table['name']); |
|
53 | + if ($table['expression']) { |
|
54 | + $join .= " ON ".$this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
55 | 55 | } |
56 | 56 | $arr[] = $join; |
57 | 57 | } |
58 | - if(count($arr)) { |
|
58 | + if (count($arr)) { |
|
59 | 59 | $query .= join("\n", $arr)."\n"; |
60 | 60 | } |
61 | 61 | return $query; |