@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | $again = true; |
40 | 40 | $new_config[$param . $glue . $key] = $value; |
41 | 41 | } |
42 | + } else { |
|
43 | + $new_config[$param] = $configure; |
|
42 | 44 | } |
43 | - else |
|
44 | - $new_config[$param] = $configure; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | return (!$again) ? $new_config : self::toUnidimensional($new_config, $glue); |
@@ -64,15 +64,17 @@ discard block |
||
64 | 64 | |
65 | 65 | do |
66 | 66 | { |
67 | - if (array_key_exists($key, $haystack)) |
|
68 | - $haystack = $haystack[$key]; |
|
69 | - else |
|
70 | - return $value; |
|
67 | + if (array_key_exists($key, $haystack)) { |
|
68 | + $haystack = $haystack[$key]; |
|
69 | + } else { |
|
70 | + return $value; |
|
71 | + } |
|
71 | 72 | |
72 | 73 | $key = count($needle) ? array_shift($needle) : NULL; |
73 | 74 | |
74 | - if (is_null($key)) |
|
75 | - return $haystack; |
|
75 | + if (is_null($key)) { |
|
76 | + return $haystack; |
|
77 | + } |
|
76 | 78 | |
77 | 79 | } while (!is_null($key)); |
78 | 80 | } |
@@ -126,7 +126,7 @@ |
||
126 | 126 | public function getContentsFromUrl($filename) |
127 | 127 | { |
128 | 128 | $headers = get_headers($url); |
129 | - $exists = stripos($headers[0],"200 OK") ? true : false; |
|
129 | + $exists = stripos($headers[0], "200 OK") ? true : false; |
|
130 | 130 | |
131 | 131 | if ($exists) |
132 | 132 | return file_get_contents($filename); |
@@ -90,13 +90,11 @@ discard block |
||
90 | 90 | try |
91 | 91 | { |
92 | 92 | $ctrl->addNonExistingError(); |
93 | - } |
|
94 | - catch (\Exception $e) |
|
93 | + } catch (\Exception $e) |
|
95 | 94 | { |
96 | 95 | $errorObject = ($e instanceof \LogicException); |
97 | 96 | $message = $e->getMessage(); |
98 | - } |
|
99 | - finally |
|
97 | + } finally |
|
100 | 98 | { |
101 | 99 | $this->assertTrue($errorObject, $message); |
102 | 100 | } |
@@ -109,18 +107,20 @@ discard block |
||
109 | 107 | |
110 | 108 | public function getContentsFromFile($filename) |
111 | 109 | { |
112 | - if (file_exists($filename)) |
|
113 | - return file_get_contents($filename); |
|
114 | - else |
|
115 | - $this->error(Errno::FILE_NOT_FOUND, $filename); |
|
110 | + if (file_exists($filename)) { |
|
111 | + return file_get_contents($filename); |
|
112 | + } else { |
|
113 | + $this->error(Errno::FILE_NOT_FOUND, $filename); |
|
114 | + } |
|
116 | 115 | } |
117 | 116 | |
118 | 117 | public function getContentsFromFileWithoutFilenameOnError($filename) |
119 | 118 | { |
120 | - if (file_exists($filename)) |
|
121 | - return file_get_contents($filename); |
|
122 | - else |
|
123 | - $this->error(Errno::FILE_NOT_FOUND); |
|
119 | + if (file_exists($filename)) { |
|
120 | + return file_get_contents($filename); |
|
121 | + } else { |
|
122 | + $this->error(Errno::FILE_NOT_FOUND); |
|
123 | + } |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | public function getContentsFromUrl($filename) |
@@ -128,10 +128,11 @@ discard block |
||
128 | 128 | $headers = get_headers($url); |
129 | 129 | $exists = stripos($headers[0],"200 OK") ? true : false; |
130 | 130 | |
131 | - if ($exists) |
|
132 | - return file_get_contents($filename); |
|
133 | - else |
|
134 | - $this->error("URL not found"); |
|
131 | + if ($exists) { |
|
132 | + return file_get_contents($filename); |
|
133 | + } else { |
|
134 | + $this->error("URL not found"); |
|
135 | + } |
|
135 | 136 | } |
136 | 137 | |
137 | 138 | public function addNonExistingError() |
@@ -92,15 +92,16 @@ discard block |
||
92 | 92 | */ |
93 | 93 | protected function _error($code, $message = null) |
94 | 94 | { |
95 | - if (!is_null($code) && !is_integer($code)) |
|
96 | - throw new \InvalidArgumentException("Invalid type given. Integer expected"); |
|
95 | + if (!is_null($code) && !is_integer($code)) { |
|
96 | + throw new \InvalidArgumentException("Invalid type given. Integer expected"); |
|
97 | + } |
|
97 | 98 | |
98 | - if (is_null($code)) |
|
99 | - $code = preg_replace('/=|\/|\+/', "", base64_encode($message)); |
|
100 | - else |
|
99 | + if (is_null($code)) { |
|
100 | + $code = preg_replace('/=|\/|\+/', "", base64_encode($message)); |
|
101 | + } else |
|
101 | 102 | { |
102 | - if (!array_key_exists($code, $this->standardErrors) && empty($message)) |
|
103 | - /* |
|
103 | + if (!array_key_exists($code, $this->standardErrors) && empty($message)) { |
|
104 | + /* |
|
104 | 105 | * "This kind of exception should lead directly to a fix in your code" |
105 | 106 | * Non-standard errors must have a message to describe the error, make sure |
106 | 107 | * you execute the error() method with a message as the second parameter. |
@@ -108,16 +109,18 @@ discard block |
||
108 | 109 | * Ref: http://php.net/manual/en/class.logicexception.php |
109 | 110 | */ |
110 | 111 | throw new \LogicException('The message does not be empty in non-standard errors!'); |
112 | + } |
|
111 | 113 | } |
112 | 114 | |
113 | - if (!array_key_exists($code, $this->errors)) |
|
114 | - $this->errors[$code] = (array_key_exists($code, $this->standardErrors)) |
|
115 | + if (!array_key_exists($code, $this->errors)) { |
|
116 | + $this->errors[$code] = (array_key_exists($code, $this->standardErrors)) |
|
115 | 117 | ? |
116 | 118 | is_null($message) |
117 | 119 | ? preg_replace('/\s\'%[a-zA-Z]*%\'/', $message, $this->standardErrors[$code]) |
118 | 120 | # if $message is not null it will replace the %file% wildcard |
119 | 121 | : preg_replace('/%[a-zA-Z]*%/', $message, $this->standardErrors[$code]) |
120 | 122 | : $message; |
123 | + } |
|
121 | 124 | } |
122 | 125 | |
123 | 126 | function __call($method, $arguments) |
@@ -127,10 +130,11 @@ discard block |
||
127 | 130 | switch (count($arguments)) |
128 | 131 | { |
129 | 132 | case 1: |
130 | - if (is_integer($arguments[0])) |
|
131 | - return call_user_func([$this, '_error'], array_shift($arguments)); |
|
132 | - else |
|
133 | - return call_user_func([$this, '_error'], null, array_shift($arguments)); |
|
133 | + if (is_integer($arguments[0])) { |
|
134 | + return call_user_func([$this, '_error'], array_shift($arguments)); |
|
135 | + } else { |
|
136 | + return call_user_func([$this, '_error'], null, array_shift($arguments)); |
|
137 | + } |
|
134 | 138 | break; |
135 | 139 | case 2: |
136 | 140 | return call_user_func([$this, '_error'], $arguments[0], $arguments[1]); |
@@ -39,13 +39,11 @@ |
||
39 | 39 | try |
40 | 40 | { |
41 | 41 | $this->assertEquals('June', Dt::getMonth(13)); |
42 | - } |
|
43 | - catch (\Exception $e) |
|
42 | + } catch (\Exception $e) |
|
44 | 43 | { |
45 | 44 | $errorObject = ($e instanceof MonthOutOfRange); |
46 | 45 | $message = $e->getMessage(); |
47 | - } |
|
48 | - finally |
|
46 | + } finally |
|
49 | 47 | { |
50 | 48 | $this->assertTrue($errorObject, $message); |
51 | 49 | } |
@@ -441,7 +441,7 @@ |
||
441 | 441 | parent::__construct($data); |
442 | 442 | $this->setTableName("MYTABLE"); |
443 | 443 | //$this->setConnectionParams("local"); |
444 | - } |
|
444 | + } |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | class MyEntityGateway extends TableGateway |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public function testCannotStablishConnectionWhenExists() |
69 | 69 | { |
70 | 70 | $options = $this->options; |
71 | - $options["dbhost"] = 'myserver'; // this server does not exists |
|
71 | + $options["dbhost"] = 'myserver'; // this server does not exists |
|
72 | 72 | |
73 | 73 | $errorObject = null; |
74 | 74 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | public function testCannotStablishConnection() |
99 | 99 | { |
100 | 100 | $options = $this->options; |
101 | - $options["dbhost"] = 'myserver'; // this server does not exists |
|
101 | + $options["dbhost"] = 'myserver'; // this server does not exists |
|
102 | 102 | |
103 | 103 | $entity = new MyEntity(); |
104 | 104 | $gateway = new TableGateway($entity, ["other" => $options]); |
@@ -78,13 +78,11 @@ discard block |
||
78 | 78 | { |
79 | 79 | $entity = new MyEntity(); |
80 | 80 | $gateway = new TableGateway($entity, ["default" => $options]); |
81 | - } |
|
82 | - catch (\Exception $e) |
|
81 | + } catch (\Exception $e) |
|
83 | 82 | { |
84 | 83 | $errorObject = ($e instanceof \RuntimeException); |
85 | 84 | $message = $e->getMessage(); |
86 | - } |
|
87 | - finally |
|
85 | + } finally |
|
88 | 86 | { |
89 | 87 | $this->assertTrue($errorObject, $message); |
90 | 88 | } |
@@ -110,13 +108,11 @@ discard block |
||
110 | 108 | try |
111 | 109 | { |
112 | 110 | $gateway->getDb()->connect(); |
113 | - } |
|
114 | - catch (\Exception $e) |
|
111 | + } catch (\Exception $e) |
|
115 | 112 | { |
116 | 113 | $errorObject = ($e instanceof ConnectionException); |
117 | 114 | $message = $e->getMessage(); |
118 | - } |
|
119 | - finally |
|
115 | + } finally |
|
120 | 116 | { |
121 | 117 | $this->assertTrue($errorObject, $message); |
122 | 118 | $this->assertNotTrue($gateway->getDb()->isConnected()); |
@@ -145,13 +141,11 @@ discard block |
||
145 | 141 | try |
146 | 142 | { |
147 | 143 | AbstractTableGateway::getDriver('other3'); |
148 | - } |
|
149 | - catch (\Exception $e) |
|
144 | + } catch (\Exception $e) |
|
150 | 145 | { |
151 | 146 | $errorObject = ($e instanceof \RuntimeException); |
152 | 147 | $message = $e->getMessage(); |
153 | - } |
|
154 | - finally |
|
148 | + } finally |
|
155 | 149 | { |
156 | 150 | $this->assertTrue($errorObject, $message); |
157 | 151 | } |
@@ -250,13 +244,11 @@ discard block |
||
250 | 244 | try |
251 | 245 | { |
252 | 246 | $gateway->wrongDML(); |
253 | - } |
|
254 | - catch (\Exception $e) |
|
247 | + } catch (\Exception $e) |
|
255 | 248 | { |
256 | 249 | $errorObject = ($e instanceof InvalidQueryException); |
257 | 250 | $message = $e->getMessage(); |
258 | - } |
|
259 | - finally |
|
251 | + } finally |
|
260 | 252 | { |
261 | 253 | $this->assertTrue($errorObject, $message); |
262 | 254 | } |
@@ -87,24 +87,25 @@ discard block |
||
87 | 87 | { |
88 | 88 | $this->currentConnection = $connection; |
89 | 89 | $this->getDriver($connection); |
90 | - } |
|
91 | - else if (is_array($connection)) |
|
90 | + } else if (is_array($connection)) |
|
92 | 91 | { |
93 | 92 | $identifier = key($connection); |
94 | 93 | $connection_options = $connection[$identifier]; |
95 | 94 | |
96 | 95 | $this->currentConnection = $identifier; |
97 | 96 | |
98 | - if (!array_key_exists('driver', $connection_options)) |
|
99 | - throw new \RuntimeException("The database driver key has not been declared"); |
|
100 | - |
|
101 | - if (!isset(self::$drivers[$identifier])) |
|
102 | - self::$drivers[$identifier] = DriverFactory::create($connection_options); |
|
103 | - else |
|
104 | - throw new \RuntimeException("The database connection already exists"); |
|
97 | + if (!array_key_exists('driver', $connection_options)) { |
|
98 | + throw new \RuntimeException("The database driver key has not been declared"); |
|
99 | + } |
|
100 | + |
|
101 | + if (!isset(self::$drivers[$identifier])) { |
|
102 | + self::$drivers[$identifier] = DriverFactory::create($connection_options); |
|
103 | + } else { |
|
104 | + throw new \RuntimeException("The database connection already exists"); |
|
105 | + } |
|
106 | + } else { |
|
107 | + throw new \InvalidArgumentException("Invalid type given. Array or string expected"); |
|
105 | 108 | } |
106 | - else |
|
107 | - throw new \InvalidArgumentException("Invalid type given. Array or string expected"); |
|
108 | 109 | } |
109 | 110 | |
110 | 111 | /** |
@@ -118,8 +119,9 @@ discard block |
||
118 | 119 | */ |
119 | 120 | public static function getDriver($identifier) |
120 | 121 | { |
121 | - if (!array_key_exists($identifier, self::$drivers)) |
|
122 | - throw new \RuntimeException("The database connection does not exists"); |
|
122 | + if (!array_key_exists($identifier, self::$drivers)) { |
|
123 | + throw new \RuntimeException("The database connection does not exists"); |
|
124 | + } |
|
123 | 125 | |
124 | 126 | return self::$drivers[$identifier]; |
125 | 127 | } |
@@ -135,8 +137,9 @@ discard block |
||
135 | 137 | */ |
136 | 138 | public static function hasDriver($identifier) |
137 | 139 | { |
138 | - if (!array_key_exists($identifier, self::$drivers)) |
|
139 | - return false; |
|
140 | + if (!array_key_exists($identifier, self::$drivers)) { |
|
141 | + return false; |
|
142 | + } |
|
140 | 143 | |
141 | 144 | return true; |
142 | 145 | } |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | { |
45 | 45 | $k++; |
46 | 46 | |
47 | - if (is_null($value)) |
|
48 | - $parsed_where[] = "$key IS NULL"; |
|
49 | - elseif ($value instanceof SQLFunction) |
|
50 | - $parsed_where[] = "$key = " . $value->getStatement(); |
|
51 | - elseif (is_array($value)) |
|
47 | + if (is_null($value)) { |
|
48 | + $parsed_where[] = "$key IS NULL"; |
|
49 | + } elseif ($value instanceof SQLFunction) { |
|
50 | + $parsed_where[] = "$key = " . $value->getStatement(); |
|
51 | + } elseif (is_array($value)) |
|
52 | 52 | { |
53 | 53 | $parsed_in = []; |
54 | 54 | |
@@ -71,8 +71,7 @@ discard block |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
74 | - } |
|
75 | - else |
|
74 | + } else |
|
76 | 75 | { |
77 | 76 | switch ($driver) |
78 | 77 | { |
@@ -90,18 +89,19 @@ discard block |
||
90 | 89 | } |
91 | 90 | |
92 | 91 | $where = "WHERE \r\n\t" . implode(" AND\r\n\t", $parsed_where); |
92 | + } else { |
|
93 | + $where = ""; |
|
93 | 94 | } |
94 | - else |
|
95 | - $where = ""; |
|
96 | 95 | |
97 | 96 | $table = $this->entity->getTableName(); |
98 | 97 | |
99 | 98 | $sql = "SELECT * \r\nFROM {$table}\r\n$where"; |
100 | 99 | |
101 | - if (count($bind_values)) |
|
102 | - $this->getDb()->execute($sql, $bind_values); |
|
103 | - else |
|
104 | - $this->getDb()->execute($sql); |
|
100 | + if (count($bind_values)) { |
|
101 | + $this->getDb()->execute($sql, $bind_values); |
|
102 | + } else { |
|
103 | + $this->getDb()->execute($sql); |
|
104 | + } |
|
105 | 105 | |
106 | 106 | return $this->getDb()->getArrayResult(); |
107 | 107 | } |
@@ -118,8 +118,9 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function insert(Array $data) |
120 | 120 | { |
121 | - if (!count($data)) |
|
122 | - throw new \LogicException("Missing values for INSERT statement!"); |
|
121 | + if (!count($data)) { |
|
122 | + throw new \LogicException("Missing values for INSERT statement!"); |
|
123 | + } |
|
123 | 124 | |
124 | 125 | $bind_values = []; |
125 | 126 | |
@@ -142,11 +143,11 @@ discard block |
||
142 | 143 | continue; |
143 | 144 | } |
144 | 145 | |
145 | - if (is_null($value)) |
|
146 | - $value = "NULL"; |
|
147 | - elseif ($value instanceof SQLFunction) |
|
148 | - $value = $value->getStatement(); |
|
149 | - else { |
|
146 | + if (is_null($value)) { |
|
147 | + $value = "NULL"; |
|
148 | + } elseif ($value instanceof SQLFunction) { |
|
149 | + $value = $value->getStatement(); |
|
150 | + } else { |
|
150 | 151 | |
151 | 152 | switch ($driver) |
152 | 153 | { |
@@ -196,11 +197,13 @@ discard block |
||
196 | 197 | { |
197 | 198 | $parsed_set = []; |
198 | 199 | |
199 | - if (!count($set)) |
|
200 | - throw new \LogicException("You cannot update rows without SET clause"); |
|
200 | + if (!count($set)) { |
|
201 | + throw new \LogicException("You cannot update rows without SET clause"); |
|
202 | + } |
|
201 | 203 | |
202 | - if (!count($where)) |
|
203 | - throw new SecurityException("You cannot update rows without WHERE clause!"); |
|
204 | + if (!count($where)) { |
|
205 | + throw new SecurityException("You cannot update rows without WHERE clause!"); |
|
206 | + } |
|
204 | 207 | |
205 | 208 | $bind_values = []; |
206 | 209 | |
@@ -212,11 +215,11 @@ discard block |
||
212 | 215 | { |
213 | 216 | $k++; |
214 | 217 | |
215 | - if (is_null($value)) |
|
216 | - $parsed_set[] = "$key = NULL"; |
|
217 | - elseif ($value instanceof SQLFunction) |
|
218 | - $parsed_set[] = "$key = " . $value->getStatement(); |
|
219 | - elseif (is_array($value)) |
|
218 | + if (is_null($value)) { |
|
219 | + $parsed_set[] = "$key = NULL"; |
|
220 | + } elseif ($value instanceof SQLFunction) { |
|
221 | + $parsed_set[] = "$key = " . $value->getStatement(); |
|
222 | + } elseif (is_array($value)) |
|
220 | 223 | { |
221 | 224 | $parsed_in = []; |
222 | 225 | |
@@ -227,8 +230,9 @@ discard block |
||
227 | 230 | case 'Oci8': |
228 | 231 | |
229 | 232 | # [POSSIBLE BUG] - To Future revision (What about non-string values ?) |
230 | - if (is_string($in_value)) |
|
231 | - $parsed_in[] = ":$k"; |
|
233 | + if (is_string($in_value)) { |
|
234 | + $parsed_in[] = ":$k"; |
|
235 | + } |
|
232 | 236 | |
233 | 237 | $bind_values[":$k"] = $in_value; |
234 | 238 | break; |
@@ -243,8 +247,7 @@ discard block |
||
243 | 247 | } |
244 | 248 | |
245 | 249 | $parsed_set[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
246 | - } |
|
247 | - else |
|
250 | + } else |
|
248 | 251 | { |
249 | 252 | switch ($driver) |
250 | 253 | { |
@@ -269,11 +272,11 @@ discard block |
||
269 | 272 | { |
270 | 273 | $k++; |
271 | 274 | |
272 | - if (is_null($value)) |
|
273 | - $parsed_where[] = "$key IS NULL"; |
|
274 | - elseif ($value instanceof SQLFunction) |
|
275 | - $parsed_where[] = "$key = " . $value->getStatement(); |
|
276 | - elseif (is_array($value)) |
|
275 | + if (is_null($value)) { |
|
276 | + $parsed_where[] = "$key IS NULL"; |
|
277 | + } elseif ($value instanceof SQLFunction) { |
|
278 | + $parsed_where[] = "$key = " . $value->getStatement(); |
|
279 | + } elseif (is_array($value)) |
|
277 | 280 | { |
278 | 281 | $parsed_in = []; |
279 | 282 | |
@@ -296,8 +299,7 @@ discard block |
||
296 | 299 | } |
297 | 300 | |
298 | 301 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
299 | - } |
|
300 | - else |
|
302 | + } else |
|
301 | 303 | { |
302 | 304 | switch ($driver) |
303 | 305 | { |
@@ -349,11 +351,11 @@ discard block |
||
349 | 351 | { |
350 | 352 | $k++; |
351 | 353 | |
352 | - if (is_null($value)) |
|
353 | - $parsed_where[] = "$key IS NULL"; |
|
354 | - elseif ($value instanceof SQLFunction) |
|
355 | - $parsed_where[] = "$key = " . $value->getStatement(); |
|
356 | - elseif (is_array($value)) |
|
354 | + if (is_null($value)) { |
|
355 | + $parsed_where[] = "$key IS NULL"; |
|
356 | + } elseif ($value instanceof SQLFunction) { |
|
357 | + $parsed_where[] = "$key = " . $value->getStatement(); |
|
358 | + } elseif (is_array($value)) |
|
357 | 359 | { |
358 | 360 | $parsed_in = []; |
359 | 361 | |
@@ -376,8 +378,7 @@ discard block |
||
376 | 378 | } |
377 | 379 | |
378 | 380 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
379 | - } |
|
380 | - else |
|
381 | + } else |
|
381 | 382 | { |
382 | 383 | switch ($driver) |
383 | 384 | { |
@@ -395,9 +396,9 @@ discard block |
||
395 | 396 | } |
396 | 397 | |
397 | 398 | $where = "\r\nWHERE \r\n\t" . implode(" AND\r\n\t", $parsed_where); |
399 | + } else { |
|
400 | + throw new SecurityException("You cannot delete rows without WHERE clause!. Use TRUNCATE statement instead."); |
|
398 | 401 | } |
399 | - else |
|
400 | - throw new SecurityException("You cannot delete rows without WHERE clause!. Use TRUNCATE statement instead."); |
|
401 | 402 | |
402 | 403 | $table = $this->entity->getTableName(); |
403 | 404 |
@@ -34,14 +34,16 @@ |
||
34 | 34 | "Sqlsrv" => "Drone\Db\Driver\SQLServer", |
35 | 35 | ]; |
36 | 36 | |
37 | - if (!array_key_exists('driver', $connection_options)) |
|
38 | - throw new \RuntimeException("The database driver key has not been declared"); |
|
37 | + if (!array_key_exists('driver', $connection_options)) { |
|
38 | + throw new \RuntimeException("The database driver key has not been declared"); |
|
39 | + } |
|
39 | 40 | |
40 | 41 | $drv = $connection_options["driver"]; |
41 | 42 | |
42 | - if (array_key_exists($drv, $drivers)) |
|
43 | - return new $drivers[$drv]($connection_options); |
|
44 | - else |
|
45 | - throw new \RuntimeException("The database driver does not exists"); |
|
43 | + if (array_key_exists($drv, $drivers)) { |
|
44 | + return new $drivers[$drv]($connection_options); |
|
45 | + } else { |
|
46 | + throw new \RuntimeException("The database driver does not exists"); |
|
47 | + } |
|
46 | 48 | } |
47 | 49 | } |
48 | 50 | \ No newline at end of file |