@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | */ |
31 | 31 | protected function buildFieldList(array $fields, array $query = array()) { |
32 | 32 | foreach ($fields as $fieldName => $fieldValue) { |
33 | - if($fieldValue instanceof DefaultValue) { |
|
33 | + if ($fieldValue instanceof DefaultValue) { |
|
34 | 34 | $fieldValue = 'DEFAULT'; |
35 | 35 | } |
36 | - if(is_array($this->mask) && !in_array($fieldName, $this->mask)) { |
|
36 | + if (is_array($this->mask) && !in_array($fieldName, $this->mask)) { |
|
37 | 37 | continue; |
38 | 38 | } |
39 | 39 | if (is_int($fieldName)) { |
40 | - if(is_array($fieldValue)) { |
|
40 | + if (is_array($fieldValue)) { |
|
41 | 41 | $fieldValue = $this->db()->quoteExpression($fieldValue[0], array_slice($fieldValue, 1)); |
42 | 42 | } |
43 | 43 | $query[] = "\t{$fieldValue}"; |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | * @return bool |
56 | 56 | */ |
57 | 57 | protected function isFieldAccessible($fieldName, array $tableFields) { |
58 | - if(!in_array($fieldName, $tableFields)) { |
|
58 | + if (!in_array($fieldName, $tableFields)) { |
|
59 | 59 | return false; |
60 | 60 | } |
61 | - if(!is_array($this->mask)) { |
|
61 | + if (!is_array($this->mask)) { |
|
62 | 62 | return true; |
63 | 63 | } |
64 | 64 | return in_array($fieldName, $this->mask); |
@@ -15,13 +15,13 @@ discard block |
||
15 | 15 | * @return int[] Insert IDs |
16 | 16 | */ |
17 | 17 | public function insertRows($rows) { |
18 | - if(!(is_array($rows) || $rows instanceof Traversable)) { |
|
18 | + if (!(is_array($rows) || $rows instanceof Traversable)) { |
|
19 | 19 | throw new BadMethodCallException('Expected $rows to by an array or an instance of \\Traversable'); |
20 | 20 | } |
21 | 21 | $result = []; |
22 | 22 | $query = $this->__toString(); |
23 | 23 | $stmt = $this->db()->prepare($query); |
24 | - foreach($rows as $row) { |
|
24 | + foreach ($rows as $row) { |
|
25 | 25 | $stmt->execute($row); |
26 | 26 | $result[] = (int) $this->db()->getLastInsertId(); |
27 | 27 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @return DDLRunnable |
34 | 34 | */ |
35 | 35 | public function prepare() { |
36 | - return $this->createPreparable($this->db()->prepare($this), function () { |
|
36 | + return $this->createPreparable($this->db()->prepare($this), function() { |
|
37 | 37 | return (int) $this->db()->getLastInsertId(); |
38 | 38 | }); |
39 | 39 | } |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | public function fetchRows(\Closure $callback = null) { |
59 | 59 | $statement = $this->createStatement(); |
60 | 60 | $data = $statement->fetchAll(\PDO::FETCH_ASSOC); |
61 | - if($this->preserveTypes) { |
|
61 | + if ($this->preserveTypes) { |
|
62 | 62 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
63 | - foreach($data as &$row) { |
|
63 | + foreach ($data as &$row) { |
|
64 | 64 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
65 | 65 | } |
66 | 66 | } |
67 | - if($callback !== null) { |
|
67 | + if ($callback !== null) { |
|
68 | 68 | $data = array_map($callback, $data); |
69 | 69 | } |
70 | 70 | $statement->closeCursor(); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @return array[]|\Generator |
77 | 77 | */ |
78 | 78 | public function fetchRowsLazy(\Closure $callback = null) { |
79 | - if(version_compare(PHP_VERSION, '5.5', '<=')) { |
|
79 | + if (version_compare(PHP_VERSION, '5.5', '<=')) { |
|
80 | 80 | return $this->fetchRows($callback); |
81 | 81 | } |
82 | 82 | $statement = $this->createStatement(); |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | public function fetchRow() { |
91 | 91 | $statement = $this->createStatement(); |
92 | 92 | $row = $statement->fetch(\PDO::FETCH_ASSOC); |
93 | - if(!is_array($row)) { |
|
93 | + if (!is_array($row)) { |
|
94 | 94 | $statement->closeCursor(); |
95 | 95 | return array(); |
96 | 96 | } |
97 | - if($this->preserveTypes) { |
|
97 | + if ($this->preserveTypes) { |
|
98 | 98 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
99 | 99 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
100 | 100 | } |
@@ -109,13 +109,13 @@ discard block |
||
109 | 109 | public function fetchKeyValue($treatValueAsArray = false) { |
110 | 110 | $rows = $this->fetchRows(); |
111 | 111 | $result = array(); |
112 | - if(!$treatValueAsArray) { |
|
113 | - foreach($rows as $row) { |
|
112 | + if (!$treatValueAsArray) { |
|
113 | + foreach ($rows as $row) { |
|
114 | 114 | list($key, $value) = array_values($row); |
115 | 115 | $result[$key] = $value; |
116 | 116 | } |
117 | 117 | } else { |
118 | - foreach($rows as $row) { |
|
118 | + foreach ($rows as $row) { |
|
119 | 119 | list($key) = array_values($row); |
120 | 120 | $result[$key] = $row; |
121 | 121 | } |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | public function fetchGroups(array $fields) { |
131 | 131 | $rows = $this->fetchRows(); |
132 | 132 | $result = array(); |
133 | - foreach($rows as $row) { |
|
133 | + foreach ($rows as $row) { |
|
134 | 134 | $tmp = &$result; |
135 | - foreach($fields as $field) { |
|
135 | + foreach ($fields as $field) { |
|
136 | 136 | $value = $row[$field]; |
137 | - if(!array_key_exists($value, $tmp)) { |
|
137 | + if (!array_key_exists($value, $tmp)) { |
|
138 | 138 | $tmp[$value] = []; |
139 | 139 | } |
140 | 140 | $tmp = &$tmp[$value]; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @return string[] |
149 | 149 | */ |
150 | 150 | public function fetchArray() { |
151 | - return $this->fetchRows(function ($row) { |
|
151 | + return $this->fetchRows(function($row) { |
|
152 | 152 | reset($row); |
153 | 153 | return current($row); |
154 | 154 | }); |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | $statement = $this->createStatement(); |
163 | 163 | $row = $statement->fetch(\PDO::FETCH_ASSOC); |
164 | 164 | $statement->closeCursor(); |
165 | - if(!is_array($row)) { |
|
165 | + if (!is_array($row)) { |
|
166 | 166 | return $default; |
167 | 167 | } |
168 | - if(!count($row)) { |
|
168 | + if (!count($row)) { |
|
169 | 169 | return null; |
170 | 170 | } |
171 | 171 | return array_shift($row); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $query = $this->__toString(); |
187 | 187 | $statement = $db->prepare($query); |
188 | 188 | $statement->execute($this->values); |
189 | - if($this->getCalcFoundRows()) { |
|
189 | + if ($this->getCalcFoundRows()) { |
|
190 | 190 | $this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn(); |
191 | 191 | } |
192 | 192 | return $statement; |
@@ -21,7 +21,7 @@ |
||
21 | 21 | * @return string |
22 | 22 | */ |
23 | 23 | protected function buildLimit($query) { |
24 | - if($this->limit !== null) { |
|
24 | + if ($this->limit !== null) { |
|
25 | 25 | $query .= "LIMIT\n\t{$this->limit}\n"; |
26 | 26 | } |
27 | 27 | return $query; |
@@ -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; |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * @return $this |
16 | 16 | */ |
17 | 17 | public function orderBy($expression, $direction = 'asc') { |
18 | - if(strtolower($direction) != 'desc') { |
|
18 | + if (strtolower($direction) != 'desc') { |
|
19 | 19 | $direction = 'ASC'; |
20 | 20 | } |
21 | - if(is_array($expression)) { |
|
22 | - if(!count($expression)) { |
|
21 | + if (is_array($expression)) { |
|
22 | + if (!count($expression)) { |
|
23 | 23 | return $this; |
24 | 24 | } |
25 | 25 | $arguments = array( |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * @return string |
38 | 38 | */ |
39 | 39 | protected function buildOrder($query) { |
40 | - if(!count($this->orderBy)) { |
|
40 | + if (!count($this->orderBy)) { |
|
41 | 41 | return $query; |
42 | 42 | } |
43 | 43 | $query .= "ORDER BY\n"; |
44 | 44 | $arr = array(); |
45 | - foreach($this->orderBy as $order) { |
|
45 | + foreach ($this->orderBy as $order) { |
|
46 | 46 | list($expression, $direction) = $order; |
47 | 47 | $arr[] = sprintf("\t%s %s", $expression, strtoupper($direction)); |
48 | 48 | } |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | * @return $this |
14 | 14 | */ |
15 | 15 | public function groupBy() { |
16 | - foreach(func_get_args() as $expression) { |
|
17 | - if(is_array($expression)) { |
|
18 | - if(!count($expression)) { |
|
16 | + foreach (func_get_args() as $expression) { |
|
17 | + if (is_array($expression)) { |
|
18 | + if (!count($expression)) { |
|
19 | 19 | continue; |
20 | 20 | } |
21 | 21 | $arguments = array( |
@@ -34,12 +34,12 @@ discard block |
||
34 | 34 | * @return string |
35 | 35 | */ |
36 | 36 | protected function buildGroups($query) { |
37 | - if(!count($this->groupBy)) { |
|
37 | + if (!count($this->groupBy)) { |
|
38 | 38 | return $query; |
39 | 39 | } |
40 | 40 | $query .= "GROUP BY\n"; |
41 | 41 | $arr = array(); |
42 | - foreach($this->groupBy as $expression) { |
|
42 | + foreach ($this->groupBy as $expression) { |
|
43 | 43 | $arr[] = "\t{$expression}"; |
44 | 44 | } |
45 | 45 | return $query.join(",\n", $arr)."\n"; |
@@ -10,17 +10,17 @@ |
||
10 | 10 | * @return string |
11 | 11 | */ |
12 | 12 | protected function buildTableName($alias, $name) { |
13 | - if(is_object($name)) { |
|
13 | + if (is_object($name)) { |
|
14 | 14 | $name = (string) $name; |
15 | 15 | $lines = explode("\n", $name); |
16 | - foreach($lines as &$line) { |
|
16 | + foreach ($lines as &$line) { |
|
17 | 17 | $line = "\t{$line}"; |
18 | 18 | } |
19 | 19 | $name = join("\n", $lines); |
20 | - $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
|
20 | + $name = '('.trim(rtrim(trim($name), ';')).')'; |
|
21 | 21 | } |
22 | 22 | $name = $this->aliasReplacer()->replace($name); |
23 | - if($alias !== null) { |
|
23 | + if ($alias !== null) { |
|
24 | 24 | return sprintf("%s %s", $name, $alias); |
25 | 25 | } |
26 | 26 | return $name; |
@@ -30,21 +30,21 @@ |
||
30 | 30 | * @return string |
31 | 31 | */ |
32 | 32 | protected function buildUnions($query) { |
33 | - $wrap = function ($query) { |
|
33 | + $wrap = function($query) { |
|
34 | 34 | $query = trim($query); |
35 | 35 | $query = join("\n\t", explode("\n", $query)); |
36 | 36 | return sprintf("(\n\t%s\n)", $query); |
37 | 37 | }; |
38 | 38 | $queries = [$wrap($query)]; |
39 | - foreach($this->unions as $unionQuery) { |
|
40 | - if($unionQuery[0] === 'ALL') { |
|
39 | + foreach ($this->unions as $unionQuery) { |
|
40 | + if ($unionQuery[0] === 'ALL') { |
|
41 | 41 | $queries[] = 'UNION ALL'; |
42 | 42 | } else { |
43 | 43 | $queries[] = 'UNION'; |
44 | 44 | } |
45 | 45 | $queries[] = $wrap($unionQuery[1]); |
46 | 46 | } |
47 | - if(count($queries) > 1) { |
|
47 | + if (count($queries) > 1) { |
|
48 | 48 | return join(" ", $queries); |
49 | 49 | } |
50 | 50 | return $query; |