@@ -20,7 +20,7 @@ |
||
20 | 20 | * @return $this |
21 | 21 | */ |
22 | 22 | public function log($query, $duration) { |
23 | - foreach($this->queryLoggers as $queryLogger) { |
|
23 | + foreach ($this->queryLoggers as $queryLogger) { |
|
24 | 24 | $queryLogger->log($query, $duration); |
25 | 25 | } |
26 | 26 | return $this; |
@@ -14,13 +14,13 @@ |
||
14 | 14 | public function throwMoreConcreteException(PDOException $exception) { |
15 | 15 | $code = $exception->errorInfo[1]; |
16 | 16 | $message = $exception->errorInfo[2]; |
17 | - if($code === 1213) { |
|
17 | + if ($code === 1213) { |
|
18 | 18 | throw new SqlDeadLockException($message, $code, $exception); |
19 | 19 | } |
20 | - if($code === 1205) { |
|
20 | + if ($code === 1205) { |
|
21 | 21 | throw new LockWaitTimeoutExceededException($message, $code, $exception); |
22 | 22 | } |
23 | - if($code === 1062) { |
|
23 | + if ($code === 1062) { |
|
24 | 24 | throw new DuplicateUniqueKeyException($message, $code, $exception); |
25 | 25 | } |
26 | 26 | throw $exception; |
@@ -19,11 +19,11 @@ |
||
19 | 19 | * @return string |
20 | 20 | */ |
21 | 21 | public function replace($name) { |
22 | - $fn = function ($values) { |
|
22 | + $fn = function($values) { |
|
23 | 23 | $alias = $values[1]; |
24 | 24 | $part = $values[2]; |
25 | 25 | $string = $this->aliasRegistry->get($alias); |
26 | - return $string . $part; |
|
26 | + return $string.$part; |
|
27 | 27 | }; |
28 | 28 | return preg_replace_callback('/^(\\w+)#(\\w+)$/', $fn, $name); |
29 | 29 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | * @return string |
24 | 24 | */ |
25 | 25 | public function get($alias) { |
26 | - if(!array_key_exists($alias, $this->aliases)) { |
|
26 | + if (!array_key_exists($alias, $this->aliases)) { |
|
27 | 27 | throw new \Exception("Alias not found: {$alias}"); |
28 | 28 | } |
29 | 29 | return $this->aliases[$alias]; |
@@ -37,17 +37,17 @@ discard block |
||
37 | 37 | * @return $this |
38 | 38 | */ |
39 | 39 | public function field($expression, $alias = null) { |
40 | - if(is_object($expression)) { |
|
40 | + if (is_object($expression)) { |
|
41 | 41 | $expression = (string) $expression; |
42 | 42 | $expression = trim($expression); |
43 | 43 | $expression = rtrim($expression, ';'); |
44 | 44 | $expression = trim($expression); |
45 | 45 | $lines = explode("\n", $expression); |
46 | - $lines = array_map(function ($line) { return "\t\t{$line}"; }, $lines); |
|
46 | + $lines = array_map(function($line) { return "\t\t{$line}"; }, $lines); |
|
47 | 47 | $expression = join("\n", $lines); |
48 | 48 | $expression = sprintf("(\n%s\n\t)", $expression); |
49 | 49 | } |
50 | - if($alias === null) { |
|
50 | + if ($alias === null) { |
|
51 | 51 | $this->fields[] = $expression; |
52 | 52 | } else { |
53 | 53 | $this->fields[$alias] = $expression; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @return $this |
61 | 61 | */ |
62 | 62 | public function fields(array $fields) { |
63 | - foreach($fields as $alias => $expression) { |
|
63 | + foreach ($fields as $alias => $expression) { |
|
64 | 64 | $this->field($expression, $alias); |
65 | 65 | } |
66 | 66 | return $this; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @return $this |
96 | 96 | */ |
97 | 97 | public function setCalcFoundRows($calcFoundRows = true) { |
98 | - if(ini_get("mysql.trace_mode")) { |
|
98 | + if (ini_get("mysql.trace_mode")) { |
|
99 | 99 | throw new \Exception('This function cant operate with mysql.trace_mode is set.'); |
100 | 100 | } |
101 | 101 | $this->calcFoundRows = $calcFoundRows; |
@@ -117,12 +117,12 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function __toString() { |
119 | 119 | $query = "SELECT"; |
120 | - if($this->calcFoundRows) { |
|
120 | + if ($this->calcFoundRows) { |
|
121 | 121 | $query .= " SQL_CALC_FOUND_ROWS"; |
122 | 122 | } |
123 | 123 | $query .= "\n"; |
124 | 124 | $query = $this->buildFields($query); |
125 | - if(count($this->getTables())) { |
|
125 | + if (count($this->getTables())) { |
|
126 | 126 | $query .= "FROM\n"; |
127 | 127 | } |
128 | 128 | $query = $this->buildTables($query); |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | */ |
145 | 145 | private function buildFields($query) { |
146 | 146 | $fields = array(); |
147 | - if(count($this->fields)) { |
|
148 | - foreach($this->fields as $alias => $expression) { |
|
149 | - if(is_numeric($alias)) { |
|
147 | + if (count($this->fields)) { |
|
148 | + foreach ($this->fields as $alias => $expression) { |
|
149 | + if (is_numeric($alias)) { |
|
150 | 150 | $fields[] = "\t{$expression}"; |
151 | 151 | } else { |
152 | 152 | $fields[] = "\t{$expression} AS `{$alias}`"; |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @return string |
164 | 164 | */ |
165 | 165 | private function buildForUpdate($query) { |
166 | - if($this->forUpdate) { |
|
166 | + if ($this->forUpdate) { |
|
167 | 167 | $query .= "FOR UPDATE\n"; |
168 | 168 | } |
169 | 169 | return $query; |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | * @return bool |
44 | 44 | */ |
45 | 45 | public function execute(array $params = []) { |
46 | - return $this->exceptionHandler(function () use ($params) { |
|
46 | + return $this->exceptionHandler(function() use ($params) { |
|
47 | 47 | $timer = microtime(true); |
48 | 48 | $response = $this->statement->execute($params); |
49 | - $this->queryLoggers->log($this->query, microtime(true) - $timer); |
|
49 | + $this->queryLoggers->log($this->query, microtime(true)-$timer); |
|
50 | 50 | return $response; |
51 | 51 | }); |
52 | 52 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function fetchAll() { |
58 | 58 | $args = func_get_args(); |
59 | - return $this->exceptionHandler(function () use ($args) { |
|
59 | + return $this->exceptionHandler(function() use ($args) { |
|
60 | 60 | return call_user_func_array([$this->statement, 'fetchAll'], $args); |
61 | 61 | }); |
62 | 62 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return mixed |
69 | 69 | */ |
70 | 70 | public function fetch($fetchStyle = PDO::FETCH_ASSOC, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { |
71 | - return $this->exceptionHandler(function () use ($fetchStyle, $cursorOrientation, $cursorOffset) { |
|
71 | + return $this->exceptionHandler(function() use ($fetchStyle, $cursorOrientation, $cursorOffset) { |
|
72 | 72 | return $this->statement->fetch($fetchStyle, $cursorOrientation, $cursorOffset); |
73 | 73 | }); |
74 | 74 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @return mixed |
79 | 79 | */ |
80 | 80 | public function fetchColumn($columnNo = 0) { |
81 | - return $this->exceptionHandler(function () use ($columnNo) { |
|
81 | + return $this->exceptionHandler(function() use ($columnNo) { |
|
82 | 82 | return $this->statement->fetchColumn($columnNo); |
83 | 83 | }); |
84 | 84 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @return bool |
88 | 88 | */ |
89 | 89 | public function closeCursor() { |
90 | - return $this->exceptionHandler(function () { |
|
90 | + return $this->exceptionHandler(function() { |
|
91 | 91 | return $this->statement->closeCursor(); |
92 | 92 | }); |
93 | 93 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @return int |
97 | 97 | */ |
98 | 98 | public function columnCount() { |
99 | - return $this->exceptionHandler(function () { |
|
99 | + return $this->exceptionHandler(function() { |
|
100 | 100 | return $this->statement->columnCount(); |
101 | 101 | }); |
102 | 102 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @return array |
107 | 107 | */ |
108 | 108 | public function getColumnMeta($columnNo) { |
109 | - return $this->exceptionHandler(function () use ($columnNo) { |
|
109 | + return $this->exceptionHandler(function() use ($columnNo) { |
|
110 | 110 | return $this->statement->getColumnMeta($columnNo); |
111 | 111 | }); |
112 | 112 | } |
@@ -24,12 +24,12 @@ |
||
24 | 24 | * @return $this |
25 | 25 | */ |
26 | 26 | public function debug($stop = true) { |
27 | - if(php_sapi_name() == 'cli') { |
|
27 | + if (php_sapi_name() == 'cli') { |
|
28 | 28 | echo "\n{$this->__toString()}\n"; |
29 | 29 | } else { |
30 | 30 | echo "<pre>{$this->__toString()}</pre>"; |
31 | 31 | } |
32 | - if($stop) { |
|
32 | + if ($stop) { |
|
33 | 33 | exit; |
34 | 34 | } |
35 | 35 | return $this; |
@@ -74,15 +74,15 @@ discard block |
||
74 | 74 | * @throws Exception |
75 | 75 | */ |
76 | 76 | public function setAll(array $data, array $allowedFields = null) { |
77 | - if($allowedFields !== null) { |
|
78 | - foreach($data as $fieldName => $value) { |
|
79 | - if(in_array($fieldName, $allowedFields)) { |
|
77 | + if ($allowedFields !== null) { |
|
78 | + foreach ($data as $fieldName => $value) { |
|
79 | + if (in_array($fieldName, $allowedFields)) { |
|
80 | 80 | $this->set($fieldName, $value); |
81 | 81 | } |
82 | 82 | } |
83 | 83 | } else { |
84 | 84 | $values = $this->clearValues($data); |
85 | - foreach($values as $fieldName => $value) { |
|
85 | + foreach ($values as $fieldName => $value) { |
|
86 | 86 | $this->set($fieldName, $value); |
87 | 87 | } |
88 | 88 | } |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | * @throws Exception |
126 | 126 | */ |
127 | 127 | private function clearValues(array $values) { |
128 | - if(!count($values)) { |
|
128 | + if (!count($values)) { |
|
129 | 129 | return []; |
130 | 130 | } |
131 | 131 | $tables = $this->getTables(); |
132 | - if(!count($tables)) { |
|
132 | + if (!count($tables)) { |
|
133 | 133 | throw new Exception('Table name is missing'); |
134 | 134 | } |
135 | - if(count($tables) > 1) { |
|
135 | + if (count($tables) > 1) { |
|
136 | 136 | throw new Exception('Batch values only work with max. one table'); |
137 | 137 | } |
138 | 138 | list($table) = $tables; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $result = array(); |
143 | 143 | |
144 | 144 | foreach ($values as $fieldName => $fieldValue) { |
145 | - if(in_array($fieldName, $fields)) { |
|
145 | + if (in_array($fieldName, $fields)) { |
|
146 | 146 | $result[$fieldName] = $fieldValue; |
147 | 147 | } |
148 | 148 | } |
@@ -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); |