@@ -49,12 +49,12 @@ discard block |
||
49 | 49 | * @var array |
50 | 50 | */ |
51 | 51 | protected $bindings = [ |
52 | - 'select' => [], |
|
53 | - 'join' => [], |
|
54 | - 'where' => [], |
|
55 | - 'having' => [], |
|
56 | - 'order' => [], |
|
57 | - 'union' => [], |
|
52 | + 'select' => [ ], |
|
53 | + 'join' => [ ], |
|
54 | + 'where' => [ ], |
|
55 | + 'having' => [ ], |
|
56 | + 'order' => [ ], |
|
57 | + 'union' => [ ], |
|
58 | 58 | ]; |
59 | 59 | |
60 | 60 | /** |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | */ |
142 | 142 | protected function addArrayOfWheres($column, string $boolean) |
143 | 143 | { |
144 | - return $this->whereNested(function ($query) use ($column) { |
|
144 | + return $this->whereNested(function($query) use ($column) { |
|
145 | 145 | |
146 | 146 | /** @var Builder $query */ |
147 | 147 | foreach ($column as $key => $value) { |
148 | 148 | if (is_numeric($key) && is_array($value)) { |
149 | - call_user_func_array([$query, 'where'], $value); |
|
149 | + call_user_func_array([ $query, 'where' ], $value); |
|
150 | 150 | } else { |
151 | 151 | $query->where($key, '=', $value); |
152 | 152 | } |
@@ -205,14 +205,14 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public function addBinding($value, $type = 'where') |
207 | 207 | { |
208 | - if (! array_key_exists($type, $this->bindings)) { |
|
208 | + if (!array_key_exists($type, $this->bindings)) { |
|
209 | 209 | throw new InvalidArgumentException("Invalid binding type: {$type}."); |
210 | 210 | } |
211 | 211 | |
212 | 212 | if (is_array($value)) { |
213 | - $this->bindings[$type] = array_values(array_merge($this->bindings[$type], $value)); |
|
213 | + $this->bindings[ $type ] = array_values(array_merge($this->bindings[ $type ], $value)); |
|
214 | 214 | } else { |
215 | - $this->bindings[$type][] = $value; |
|
215 | + $this->bindings[ $type ][ ] = $value; |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | return $this; |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * @param array|mixed $columns |
246 | 246 | * @return $this |
247 | 247 | */ |
248 | - public function select($columns = ['*']) |
|
248 | + public function select($columns = [ '*' ]) |
|
249 | 249 | { |
250 | 250 | $this->columns = is_array($columns) ? $columns : func_get_args(); |
251 | 251 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * @param array $bindings |
258 | 258 | * @return mixed |
259 | 259 | */ |
260 | - public function selectRaw(string $query, array $bindings = []) |
|
260 | + public function selectRaw(string $query, array $bindings = [ ]) |
|
261 | 261 | { |
262 | 262 | return $this->connection->select($query, $bindings); |
263 | 263 | } |
@@ -272,8 +272,8 @@ discard block |
||
272 | 272 | return true; |
273 | 273 | } |
274 | 274 | |
275 | - if (! is_array(reset($values))) { |
|
276 | - $values = [$values]; |
|
275 | + if (!is_array(reset($values))) { |
|
276 | + $values = [ $values ]; |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | // Here, we will sort the insert keys for every record so that each insert is |
@@ -282,18 +282,18 @@ discard block |
||
282 | 282 | else { |
283 | 283 | foreach ($values as $key => $value) { |
284 | 284 | ksort($value); |
285 | - $values[$key] = $value; |
|
285 | + $values[ $key ] = $value; |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 | |
289 | 289 | // We'll treat every insert like a batch insert so we can easily insert each |
290 | 290 | // of the records into the database consistently. This will make it much |
291 | 291 | // easier on the grammars to just handle one type of record insertion. |
292 | - $bindings = []; |
|
292 | + $bindings = [ ]; |
|
293 | 293 | |
294 | 294 | foreach ($values as $record) { |
295 | 295 | foreach ($record as $value) { |
296 | - $bindings[] = $value; |
|
296 | + $bindings[ ] = $value; |
|
297 | 297 | } |
298 | 298 | } |
299 | 299 | |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | { |
349 | 349 | $wrapped = $this->grammar->wrap($column); |
350 | 350 | |
351 | - $columns = array_merge([$column => $this->raw("$wrapped + $amount")]); |
|
351 | + $columns = array_merge([ $column => $this->raw("$wrapped + $amount") ]); |
|
352 | 352 | |
353 | 353 | return $this->update($columns); |
354 | 354 | } |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | { |
365 | 365 | $wrapped = $this->grammar->wrap($column); |
366 | 366 | |
367 | - $columns = array_merge([$column => $this->raw("$wrapped - $amount")]); |
|
367 | + $columns = array_merge([ $column => $this->raw("$wrapped - $amount") ]); |
|
368 | 368 | |
369 | 369 | return $this->update($columns); |
370 | 370 | } |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | // If an ID is passed to the method, we will set the where clause to check |
381 | 381 | // the ID to allow developers to simply and quickly remove a single row |
382 | 382 | // from their database without manually specifying the where clauses. |
383 | - if (! is_null($id)) { |
|
383 | + if (!is_null($id)) { |
|
384 | 384 | $this->where('id', '=', $id); |
385 | 385 | } |
386 | 386 | |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | * @param array $bindings |
407 | 407 | * @return bool |
408 | 408 | */ |
409 | - public function insertRaw(string $query, array $bindings = []) |
|
409 | + public function insertRaw(string $query, array $bindings = [ ]) |
|
410 | 410 | { |
411 | 411 | return $this->connection->insert($query, $bindings); |
412 | 412 | } |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | * @param array $bindings |
417 | 417 | * @return int |
418 | 418 | */ |
419 | - public function updateRaw(string $query, array $bindings = []) |
|
419 | + public function updateRaw(string $query, array $bindings = [ ]) |
|
420 | 420 | { |
421 | 421 | return $this->connection->update($query, $bindings); |
422 | 422 | } |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * @param array $bindings |
427 | 427 | * @return int |
428 | 428 | */ |
429 | - public function deleteRaw(string $query, array $bindings = []) |
|
429 | + public function deleteRaw(string $query, array $bindings = [ ]) |
|
430 | 430 | { |
431 | 431 | return $this->connection->delete($query, $bindings); |
432 | 432 | } |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | // passed to the method, we will assume that the operator is an equals sign |
467 | 467 | // and keep going. Otherwise, we'll require the operator to be passed in. |
468 | 468 | if (func_num_args() == 2) { |
469 | - list($value, $operator) = [$operator, '=']; |
|
469 | + list($value, $operator) = [ $operator, '=' ]; |
|
470 | 470 | } elseif ($this->invalidOperatorAndValue($operator, $value)) { |
471 | 471 | throw new InvalidArgumentException('Illegal operator and value combination.'); |
472 | 472 | } |
@@ -474,8 +474,8 @@ discard block |
||
474 | 474 | // If the given operator is not found in the list of valid operators we will |
475 | 475 | // assume that the developer is just short-cutting the '=' operators and |
476 | 476 | // we will set the operators to '=' and set the values appropriately. |
477 | - if (! in_array(strtolower($operator), $this->operators, true)) { |
|
478 | - list($value, $operator) = [$operator, '=']; |
|
477 | + if (!in_array(strtolower($operator), $this->operators, true)) { |
|
478 | + list($value, $operator) = [ $operator, '=' ]; |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | // If the value is a Closure, it means the developer is performing an entire |
@@ -497,9 +497,9 @@ discard block |
||
497 | 497 | // will be bound to each SQL statements when it is finally executed. |
498 | 498 | $type = 'Basic'; |
499 | 499 | |
500 | - $this->wheres[] = compact('type', 'column', 'operator', 'value', 'boolean'); |
|
500 | + $this->wheres[ ] = compact('type', 'column', 'operator', 'value', 'boolean'); |
|
501 | 501 | |
502 | - if (! $value instanceof Expression) { |
|
502 | + if (!$value instanceof Expression) { |
|
503 | 503 | $this->addBinding($value, 'where'); |
504 | 504 | } |
505 | 505 | |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | { |
520 | 520 | $type = 'in'; |
521 | 521 | |
522 | - $this->wheres[] = compact('column', 'type', 'boolean', 'not'); |
|
522 | + $this->wheres[ ] = compact('column', 'type', 'boolean', 'not'); |
|
523 | 523 | |
524 | 524 | $this->addBinding($values, 'where'); |
525 | 525 | |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | { |
577 | 577 | $type = 'between'; |
578 | 578 | |
579 | - $this->wheres[] = compact('column', 'type', 'boolean', 'not'); |
|
579 | + $this->wheres[ ] = compact('column', 'type', 'boolean', 'not'); |
|
580 | 580 | |
581 | 581 | $this->addBinding($values, 'where'); |
582 | 582 | |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | if (count($query->wheres)) { |
661 | 661 | $type = 'Nested'; |
662 | 662 | |
663 | - $this->wheres[] = compact('type', 'query', 'boolean'); |
|
663 | + $this->wheres[ ] = compact('type', 'query', 'boolean'); |
|
664 | 664 | |
665 | 665 | $this->addBinding($query->getBindings(), 'where'); |
666 | 666 | } |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | // in the array of where clauses for the "main" parent query instance. |
689 | 689 | call_user_func($callback, $query); |
690 | 690 | |
691 | - $this->wheres[] = compact('type', 'column', 'operator', 'query', 'boolean'); |
|
691 | + $this->wheres[ ] = compact('type', 'column', 'operator', 'query', 'boolean'); |
|
692 | 692 | |
693 | 693 | $this->addBinding($query->getBindings(), 'where'); |
694 | 694 | |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | { |
708 | 708 | $type = 'Null'; |
709 | 709 | |
710 | - $this->wheres[] = compact('type', 'column', 'boolean', 'not'); |
|
710 | + $this->wheres[ ] = compact('type', 'column', 'boolean', 'not'); |
|
711 | 711 | |
712 | 712 | return $this; |
713 | 713 | } |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | */ |
828 | 828 | protected function addDateBasedWhere($type, $column, $operator, $value, $boolean = 'and') |
829 | 829 | { |
830 | - $this->wheres[] = compact('column', 'type', 'boolean', 'operator', 'value'); |
|
830 | + $this->wheres[ ] = compact('column', 'type', 'boolean', 'operator', 'value'); |
|
831 | 831 | |
832 | 832 | $this->addBinding($value, 'where'); |
833 | 833 | |
@@ -843,11 +843,11 @@ discard block |
||
843 | 843 | */ |
844 | 844 | public function orderBy($column, $direction = 'asc') |
845 | 845 | { |
846 | - if(!($direction == 'asc' or $direction == 'desc')) { |
|
846 | + if (!($direction == 'asc' or $direction == 'desc')) { |
|
847 | 847 | handle(new Exception("Order by direction invalid: '".$direction."'")); |
848 | 848 | } |
849 | 849 | |
850 | - $column = is_array($column) ? $column : [$column]; |
|
850 | + $column = is_array($column) ? $column : [ $column ]; |
|
851 | 851 | |
852 | 852 | $this->orders = [ |
853 | 853 | $column, |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | * @param array $columns |
892 | 892 | * @return ArrayObject|null |
893 | 893 | */ |
894 | - public function get(array $columns = ['*'], $executeSQLWithoutSeprateBindings = false) |
|
894 | + public function get(array $columns = [ '*' ], $executeSQLWithoutSeprateBindings = false) |
|
895 | 895 | { |
896 | 896 | $this->columns = $columns; |
897 | 897 | |
@@ -907,7 +907,7 @@ discard block |
||
907 | 907 | |
908 | 908 | // To fix issue #62 |
909 | 909 | // @link https://github.com/FramyFramework/Framy/issues/62 |
910 | - $result->map(function ($item) { |
|
910 | + $result->map(function($item) { |
|
911 | 911 | $item->exists = true; |
912 | 912 | }); |
913 | 913 | |
@@ -968,11 +968,11 @@ discard block |
||
968 | 968 | * @param array $columns |
969 | 969 | * @return Model |
970 | 970 | */ |
971 | - public function first(array $columns = ['*']) |
|
971 | + public function first(array $columns = [ '*' ]) |
|
972 | 972 | { |
973 | 973 | $this->limit(1); |
974 | 974 | |
975 | - return $this->get($columns)[0]; |
|
975 | + return $this->get($columns)[ 0 ]; |
|
976 | 976 | } |
977 | 977 | |
978 | 978 | /** |
@@ -983,7 +983,7 @@ discard block |
||
983 | 983 | */ |
984 | 984 | public function value(string $val) |
985 | 985 | { |
986 | - return $this->first([$val])->$val; |
|
986 | + return $this->first([ $val ])->$val; |
|
987 | 987 | } |
988 | 988 | |
989 | 989 | /** |
@@ -994,8 +994,8 @@ discard block |
||
994 | 994 | */ |
995 | 995 | public function count($columns = '*') |
996 | 996 | { |
997 | - if (! is_array($columns)) { |
|
998 | - $columns = [$columns]; |
|
997 | + if (!is_array($columns)) { |
|
998 | + $columns = [ $columns ]; |
|
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | return (int) $this->aggregate(__FUNCTION__, $columns); |
@@ -1009,7 +1009,7 @@ discard block |
||
1009 | 1009 | */ |
1010 | 1010 | public function min(string $column) |
1011 | 1011 | { |
1012 | - return $this->aggregate(__FUNCTION__, [$column]); |
|
1012 | + return $this->aggregate(__FUNCTION__, [ $column ]); |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | /** |
@@ -1020,7 +1020,7 @@ discard block |
||
1020 | 1020 | */ |
1021 | 1021 | public function max($column) |
1022 | 1022 | { |
1023 | - return $this->aggregate(__FUNCTION__, [$column]); |
|
1023 | + return $this->aggregate(__FUNCTION__, [ $column ]); |
|
1024 | 1024 | } |
1025 | 1025 | |
1026 | 1026 | /** |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | */ |
1032 | 1032 | public function sum($column) |
1033 | 1033 | { |
1034 | - $result = $this->aggregate(__FUNCTION__, [$column]); |
|
1034 | + $result = $this->aggregate(__FUNCTION__, [ $column ]); |
|
1035 | 1035 | |
1036 | 1036 | return $result ?: 0; |
1037 | 1037 | } |
@@ -1044,7 +1044,7 @@ discard block |
||
1044 | 1044 | */ |
1045 | 1045 | public function avg($column) |
1046 | 1046 | { |
1047 | - return $this->aggregate(__FUNCTION__, [$column]); |
|
1047 | + return $this->aggregate(__FUNCTION__, [ $column ]); |
|
1048 | 1048 | } |
1049 | 1049 | |
1050 | 1050 | /** |
@@ -1079,10 +1079,10 @@ discard block |
||
1079 | 1079 | |
1080 | 1080 | $results = $this->connection->select($sql); |
1081 | 1081 | |
1082 | - if (isset($results[0])) { |
|
1083 | - $results = (array) $results[0]; |
|
1082 | + if (isset($results[ 0 ])) { |
|
1083 | + $results = (array) $results[ 0 ]; |
|
1084 | 1084 | |
1085 | - return (bool) $results['exists']; |
|
1085 | + return (bool) $results[ 'exists' ]; |
|
1086 | 1086 | } |
1087 | 1087 | |
1088 | 1088 | return false; |
@@ -1095,7 +1095,7 @@ discard block |
||
1095 | 1095 | */ |
1096 | 1096 | public function doesntExist() |
1097 | 1097 | { |
1098 | - return ! $this->exists(); |
|
1098 | + return !$this->exists(); |
|
1099 | 1099 | } |
1100 | 1100 | |
1101 | 1101 | /** |
@@ -1105,7 +1105,7 @@ discard block |
||
1105 | 1105 | * @param array $columns |
1106 | 1106 | * @return float|int |
1107 | 1107 | */ |
1108 | - public function aggregate($function, $columns = ['*']) |
|
1108 | + public function aggregate($function, $columns = [ '*' ]) |
|
1109 | 1109 | { |
1110 | 1110 | $this->aggregate = compact('function', 'columns'); |
1111 | 1111 | |
@@ -1120,10 +1120,10 @@ discard block |
||
1120 | 1120 | |
1121 | 1121 | $this->columns = $previousColumns; |
1122 | 1122 | |
1123 | - if (isset($results[0])) { |
|
1124 | - $result = array_change_key_case((array) $results[0]); |
|
1123 | + if (isset($results[ 0 ])) { |
|
1124 | + $result = array_change_key_case((array) $results[ 0 ]); |
|
1125 | 1125 | |
1126 | - return $result['aggregate']; |
|
1126 | + return $result[ 'aggregate' ]; |
|
1127 | 1127 | } |
1128 | 1128 | } |
1129 | 1129 | |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | private function isOperatorValid($operatorToCheck) |
1139 | 1139 | { |
1140 | 1140 | foreach ($this->operators as $operator) { |
1141 | - if($operatorToCheck === $operator) { |
|
1141 | + if ($operatorToCheck === $operator) { |
|
1142 | 1142 | return true; |
1143 | 1143 | } |
1144 | 1144 | } |
@@ -1164,8 +1164,8 @@ discard block |
||
1164 | 1164 | */ |
1165 | 1165 | protected function cleanBindings(array $bindings) |
1166 | 1166 | { |
1167 | - return array_values(array_filter($bindings, function ($binding) { |
|
1168 | - return ! $binding instanceof Expression; |
|
1167 | + return array_values(array_filter($bindings, function($binding) { |
|
1168 | + return !$binding instanceof Expression; |
|
1169 | 1169 | })); |
1170 | 1170 | } |
1171 | 1171 | |
@@ -1179,13 +1179,13 @@ discard block |
||
1179 | 1179 | protected function prepareRawQuery(string $query, array $bindings): string |
1180 | 1180 | { |
1181 | 1181 | // search for values in query |
1182 | - preg_match_all("/:([^ ]*)/", $query,$values); |
|
1182 | + preg_match_all("/:([^ ]*)/", $query, $values); |
|
1183 | 1183 | |
1184 | 1184 | // replace values with bindings |
1185 | - foreach ($values[1] as $value) { |
|
1185 | + foreach ($values[ 1 ] as $value) { |
|
1186 | 1186 | // check if fitting binding exists |
1187 | - if(array_key_exists($value, $bindings)) { |
|
1188 | - $query = str_replace(":".$value, $bindings[$value], $query); |
|
1187 | + if (array_key_exists($value, $bindings)) { |
|
1188 | + $query = str_replace(":".$value, $bindings[ $value ], $query); |
|
1189 | 1189 | } else { |
1190 | 1190 | handle(new Exception("Could not find fitting value '$value' in bindings for query: '$query'")); |
1191 | 1191 | } |
@@ -77,14 +77,14 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @var array |
79 | 79 | */ |
80 | - protected $attributes = []; |
|
80 | + protected $attributes = [ ]; |
|
81 | 81 | |
82 | 82 | /** |
83 | 83 | * The model attribute's original state. |
84 | 84 | * |
85 | 85 | * @var array |
86 | 86 | */ |
87 | - protected $original = []; |
|
87 | + protected $original = [ ]; |
|
88 | 88 | |
89 | 89 | /** |
90 | 90 | * The number of models to return for pagination. |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * Model constructor. |
120 | 120 | * @param array $attributes |
121 | 121 | */ |
122 | - public function __construct(array $attributes = []) |
|
122 | + public function __construct(array $attributes = [ ]) |
|
123 | 123 | { |
124 | 124 | $this->bootIfNotBooted(); |
125 | 125 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function bootIfNotBooted() |
140 | 140 | { |
141 | - if (! self::$isBooted) { |
|
141 | + if (!self::$isBooted) { |
|
142 | 142 | self::boot(); |
143 | 143 | |
144 | 144 | self::$isBooted = true; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function syncOriginalAttribute($attribute) |
167 | 167 | { |
168 | - $this->original[$attribute] = $this->attributes[$attribute]; |
|
168 | + $this->original[ $attribute ] = $this->attributes[ $attribute ]; |
|
169 | 169 | |
170 | 170 | return $this; |
171 | 171 | } |
@@ -295,13 +295,13 @@ discard block |
||
295 | 295 | * @throws ConnectionNotConfiguredException |
296 | 296 | * @throws StringObjectException |
297 | 297 | */ |
298 | - public static function all(array $columns = ['*']) |
|
298 | + public static function all(array $columns = [ '*' ]) |
|
299 | 299 | { |
300 | 300 | $instance = new static(); |
301 | 301 | /** @var ArrayObject $result */ |
302 | 302 | $result = $instance->newQuery()->get($columns); |
303 | 303 | |
304 | - $result->map(function ($item) { |
|
304 | + $result->map(function($item) { |
|
305 | 305 | $item->exists = true; |
306 | 306 | }); |
307 | 307 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | $instance = new static(); |
320 | 320 | $result = $instance->newQuery()->find($id); |
321 | 321 | |
322 | - if (! is_null($result)) { |
|
322 | + if (!is_null($result)) { |
|
323 | 323 | $result->exists = true; |
324 | 324 | } |
325 | 325 | |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | { |
358 | 358 | $instance = new static(); |
359 | 359 | |
360 | - if (! is_array($id)) { |
|
361 | - $id = [$id]; |
|
360 | + if (!is_array($id)) { |
|
361 | + $id = [ $id ]; |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | return $instance->newQuery()->remove($id); |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | */ |
391 | 391 | public function setAttribute($key, $value) |
392 | 392 | { |
393 | - $this->attributes[$key] = $value; |
|
393 | + $this->attributes[ $key ] = $value; |
|
394 | 394 | |
395 | 395 | return $this; |
396 | 396 | } |
@@ -408,11 +408,11 @@ discard block |
||
408 | 408 | */ |
409 | 409 | public function getAttribute($key) |
410 | 410 | { |
411 | - if (! $key) { |
|
411 | + if (!$key) { |
|
412 | 412 | return; |
413 | 413 | } |
414 | 414 | |
415 | - $attr = $this->getAttributes()[$key]; |
|
415 | + $attr = $this->getAttributes()[ $key ]; |
|
416 | 416 | |
417 | 417 | if (isset($attr)) { |
418 | 418 | return $attr; |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | */ |
585 | 585 | public function offsetExists($offset) |
586 | 586 | { |
587 | - return isset($this->attributes[$offset]); |
|
587 | + return isset($this->attributes[ $offset ]); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | /** |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | */ |
599 | 599 | public function offsetGet($offset) |
600 | 600 | { |
601 | - return $this->attributes[$offset]; |
|
601 | + return $this->attributes[ $offset ]; |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | /** |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | */ |
616 | 616 | public function offsetSet($offset, $value) |
617 | 617 | { |
618 | - $this->attributes[$offset] = $value; |
|
618 | + $this->attributes[ $offset ] = $value; |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | */ |
630 | 630 | public function offsetUnset($offset) |
631 | 631 | { |
632 | - unset($this->attributes[$offset]); |
|
632 | + unset($this->attributes[ $offset ]); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | /** |
@@ -698,11 +698,11 @@ discard block |
||
698 | 698 | { |
699 | 699 | $time = $this->freshTimestamp(); |
700 | 700 | |
701 | - if (! is_null(static::UPDATED_AT) ) { |
|
701 | + if (!is_null(static::UPDATED_AT)) { |
|
702 | 702 | $this->setUpdatedAt($time); |
703 | 703 | } |
704 | 704 | |
705 | - if (! is_null(static::CREATED_AT)) { |
|
705 | + if (!is_null(static::CREATED_AT)) { |
|
706 | 706 | $this->setCreatedAt($time); |
707 | 707 | } |
708 | 708 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @var array |
88 | 88 | */ |
89 | - protected $middleware = []; |
|
89 | + protected $middleware = [ ]; |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Methods |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | if (!is_string($callback)) { |
134 | 134 | if (!is_callable($callback)) { |
135 | 135 | throw new InvalidArgumentException( |
136 | - 'Expected a callable or string. Got an uncallable or not string'. gettype($callback) |
|
136 | + 'Expected a callable or string. Got an uncallable or not string'.gettype($callback) |
|
137 | 137 | ); |
138 | 138 | } |
139 | 139 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | { |
188 | 188 | // Allow null, otherwise expect an array or a string |
189 | 189 | if (null !== $method && !is_array($method) && !is_string($method)) { |
190 | - throw new InvalidArgumentException('Expected an array or string. Got a '. gettype($method)); |
|
190 | + throw new InvalidArgumentException('Expected an array or string. Got a '.gettype($method)); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | $this->method = $method; |
@@ -267,15 +267,15 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function middleware(string $name) |
269 | 269 | { |
270 | - $obj = $this->getFromConfig("middleware")[$name]; |
|
270 | + $obj = $this->getFromConfig("middleware")[ $name ]; |
|
271 | 271 | |
272 | 272 | if (is_null($obj)) { |
273 | - $obj = $this->getFromConfig("groups")[$name]; |
|
273 | + $obj = $this->getFromConfig("groups")[ $name ]; |
|
274 | 274 | |
275 | 275 | $this->doesMiddlewareExist($obj); |
276 | 276 | } |
277 | 277 | |
278 | - $this->middleware[$name] = $obj; |
|
278 | + $this->middleware[ $name ] = $obj; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -302,20 +302,20 @@ discard block |
||
302 | 302 | private function createInstances(array $middleware) |
303 | 303 | { |
304 | 304 | // to handle the case where no global middleware is configured |
305 | - if($middleware == []) { |
|
305 | + if ($middleware == [ ]) { |
|
306 | 306 | return; |
307 | 307 | } |
308 | 308 | |
309 | 309 | foreach ($middleware as $name => $class) { |
310 | 310 | if (is_array($class)) { |
311 | 311 | foreach ($class as $key => $value) { |
312 | - if($this->doesMiddlewareExist($value)) { |
|
313 | - $this->middleware[$name][$key] = new $value; |
|
312 | + if ($this->doesMiddlewareExist($value)) { |
|
313 | + $this->middleware[ $name ][ $key ] = new $value; |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | } else { |
317 | - if($this->doesMiddlewareExist($class)) { |
|
318 | - $this->middleware[$name] = new $class; |
|
317 | + if ($this->doesMiddlewareExist($class)) { |
|
318 | + $this->middleware[ $name ] = new $class; |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | } |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | } else { |
334 | 334 | // if $fullyQualifiedClassName is object we dont throw an |
335 | 335 | // exception because middleware was already created. |
336 | - if (! is_object($fullyQualifiedClassName)) { |
|
336 | + if (!is_object($fullyQualifiedClassName)) { |
|
337 | 337 | throw new MiddlewareNotFoundException("Middleware `%s` not found", $fullyQualifiedClassName); |
338 | 338 | } |
339 | 339 |
@@ -401,8 +401,8 @@ |
||
401 | 401 | public function dispatch( |
402 | 402 | Request $request = null, |
403 | 403 | AbstractResponse $response = null, |
404 | - $send_response = true, |
|
405 | - $capture = self::DISPATCH_NO_CAPTURE |
|
404 | + $send_response = true, |
|
405 | + $capture = self::DISPATCH_NO_CAPTURE |
|
406 | 406 | ) { |
407 | 407 | // Set/Initialize our objects to be sent in each callback |
408 | 408 | $this->request = $request ?: Request::createFromGlobals(); |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | AbstractRouteFactory $route_factory = null |
209 | 209 | ) { |
210 | 210 | // Instantiate and fall back to defaults |
211 | - $this->service = $service ?: new ServiceProvider(); |
|
212 | - $this->app = $app ?: new App(); |
|
213 | - $this->routes = $routes ?: new RouteCollection(); |
|
211 | + $this->service = $service ?: new ServiceProvider(); |
|
212 | + $this->app = $app ?: new App(); |
|
213 | + $this->routes = $routes ?: new RouteCollection(); |
|
214 | 214 | $this->route_factory = $route_factory ?: new RouteFactory(); |
215 | 215 | |
216 | 216 | $this->error_callbacks = new SplStack(); |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | $capture = self::DISPATCH_NO_CAPTURE |
406 | 406 | ) { |
407 | 407 | // Set/Initialize our objects to be sent in each callback |
408 | - $this->request = $request ?: Request::createFromGlobals(); |
|
408 | + $this->request = $request ?: Request::createFromGlobals(); |
|
409 | 409 | $this->response = $response ?: new Response(); |
410 | 410 | |
411 | 411 | // Bind our objects to our service |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | // Test for HEAD request (like GET) |
469 | 469 | if (strcasecmp($req_method, 'HEAD') === 0 |
470 | 470 | && (strcasecmp($method, 'HEAD') === 0 |
471 | - || strcasecmp($method, 'GET') === 0 ) |
|
471 | + || strcasecmp($method, 'GET') === 0) |
|
472 | 472 | ) { |
473 | 473 | |
474 | 474 | $method_match = true; |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | $possible_match = (null === $method_match) || $method_match; |
482 | 482 | |
483 | 483 | // ! is used to negate a match |
484 | - if (isset($path[0]) && $path[0] === '!') { |
|
484 | + if (isset($path[ 0 ]) && $path[ 0 ] === '!') { |
|
485 | 485 | $negate = true; |
486 | 486 | $i = 1; |
487 | 487 | } else { |
@@ -506,10 +506,10 @@ discard block |
||
506 | 506 | |
507 | 507 | continue; |
508 | 508 | |
509 | - } elseif (isset($path[$i]) && $path[$i] === '@') { |
|
509 | + } elseif (isset($path[ $i ]) && $path[ $i ] === '@') { |
|
510 | 510 | // @ is used to specify custom regex |
511 | 511 | |
512 | - $match = preg_match('`' . substr($path, $i + 1) . '`', $uri, $params); |
|
512 | + $match = preg_match('`'.substr($path, $i + 1).'`', $uri, $params); |
|
513 | 513 | |
514 | 514 | } else { |
515 | 515 | // Compiling and matching regular expressions is relatively |
@@ -518,25 +518,25 @@ discard block |
||
518 | 518 | $expression = null; |
519 | 519 | $regex = false; |
520 | 520 | $j = 0; |
521 | - $n = isset($path[$i]) ? $path[$i] : null; |
|
521 | + $n = isset($path[ $i ]) ? $path[ $i ] : null; |
|
522 | 522 | |
523 | 523 | // Find the longest non-regex substring and match it against the URI |
524 | 524 | while (true) { |
525 | - if (!isset($path[$i])) { |
|
525 | + if (!isset($path[ $i ])) { |
|
526 | 526 | break; |
527 | 527 | } elseif (false === $regex) { |
528 | 528 | $c = $n; |
529 | 529 | $regex = $c === '[' || $c === '(' || $c === '.'; |
530 | - if (false === $regex && false !== isset($path[$i+1])) { |
|
531 | - $n = $path[$i + 1]; |
|
530 | + if (false === $regex && false !== isset($path[ $i + 1 ])) { |
|
531 | + $n = $path[ $i + 1 ]; |
|
532 | 532 | $regex = $n === '?' || $n === '+' || $n === '*' || $n === '{'; |
533 | 533 | } |
534 | - if (false === $regex && $c !== '/' && (!isset($uri[$j]) || $c !== $uri[$j])) { |
|
534 | + if (false === $regex && $c !== '/' && (!isset($uri[ $j ]) || $c !== $uri[ $j ])) { |
|
535 | 535 | continue 2; |
536 | 536 | } |
537 | 537 | $j++; |
538 | 538 | } |
539 | - $expression .= $path[$i++]; |
|
539 | + $expression .= $path[ $i++ ]; |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | try { |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | |
645 | 645 | } else { |
646 | 646 | // Output capturing behavior |
647 | - switch($capture) { |
|
647 | + switch ($capture) { |
|
648 | 648 | case self::DISPATCH_CAPTURE_AND_RETURN: |
649 | 649 | $buffed_content = null; |
650 | 650 | while (ob_get_level() >= $this->output_buffer_level) { |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | protected function doMiddleware(Route $route) |
708 | 708 | { |
709 | 709 | /** @var MiddlewareInterface $middleware */ |
710 | - foreach($route->getMiddleware() as $middleware) { |
|
710 | + foreach ($route->getMiddleware() as $middleware) { |
|
711 | 711 | if (is_array($middleware)) { |
712 | 712 | foreach ($middleware as $group) { |
713 | 713 | $group->handle($this->request()); |
@@ -728,8 +728,8 @@ discard block |
||
728 | 728 | // First escape all of the non-named param (non [block]s) for regex-chars |
729 | 729 | $route = preg_replace_callback( |
730 | 730 | static::ROUTE_ESCAPE_REGEX, |
731 | - function ($match) { |
|
732 | - return preg_quote($match[0]); |
|
731 | + function($match) { |
|
732 | + return preg_quote($match[ 0 ]); |
|
733 | 733 | }, |
734 | 734 | $route |
735 | 735 | ); |
@@ -740,11 +740,11 @@ discard block |
||
740 | 740 | // Now let's actually compile the path |
741 | 741 | $route = preg_replace_callback( |
742 | 742 | static::ROUTE_COMPILE_REGEX, |
743 | - function ($match) use ($match_types) { |
|
743 | + function($match) use ($match_types) { |
|
744 | 744 | list(, $pre, $type, $param, $optional) = $match; |
745 | 745 | |
746 | - if (isset($match_types[$type])) { |
|
747 | - $type = $match_types[$type]; |
|
746 | + if (isset($match_types[ $type ])) { |
|
747 | + $type = $match_types[ $type ]; |
|
748 | 748 | } |
749 | 749 | |
750 | 750 | // Older versions of PCRE require the 'P' in (?P<named>) |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | |
786 | 786 | // Set an error handler temporarily |
787 | 787 | set_error_handler( |
788 | - function ($errno, $errstr) use (&$error_string) { |
|
788 | + function($errno, $errstr) use (&$error_string) { |
|
789 | 789 | $error_string = $errstr; |
790 | 790 | }, |
791 | 791 | E_NOTICE | E_WARNING |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | |
839 | 839 | // Make sure we are getting a valid route |
840 | 840 | if (null === $route) { |
841 | - throw new OutOfBoundsException('No such route with name: '. $route_name); |
|
841 | + throw new OutOfBoundsException('No such route with name: '.$route_name); |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | $path = $route->getPath(); |
@@ -846,11 +846,11 @@ discard block |
||
846 | 846 | // Use our compilation regex to reverse the path's compilation from its definition |
847 | 847 | $reversed_path = preg_replace_callback( |
848 | 848 | static::ROUTE_COMPILE_REGEX, |
849 | - function ($match) use ($params) { |
|
850 | - list($block, $pre, , $param, $optional) = $match; |
|
849 | + function($match) use ($params) { |
|
850 | + list($block, $pre,, $param, $optional) = $match; |
|
851 | 851 | |
852 | - if (isset($params[$param])) { |
|
853 | - return $pre. $params[$param]; |
|
852 | + if (isset($params[ $param ])) { |
|
853 | + return $pre.$params[ $param ]; |
|
854 | 854 | } elseif ($optional) { |
855 | 855 | return ''; |
856 | 856 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | use app\framework\Component\Validation\ValidationException; |
12 | 12 | use app\framework\Component\Validation\ValidatorInterface; |
13 | 13 | |
14 | -class Email implements ValidatorInterface{ |
|
14 | +class Email implements ValidatorInterface { |
|
15 | 15 | /** |
16 | 16 | * Get validator name, eg: email |
17 | 17 | * |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @return boolean|string |
33 | 33 | * @throws ValidationException |
34 | 34 | */ |
35 | - public function validate($value, $params = [], $throw = true) |
|
35 | + public function validate($value, $params = [ ], $throw = true) |
|
36 | 36 | { |
37 | 37 | if (filter_var($value, FILTER_VALIDATE_EMAIL)) { |
38 | 38 | return true; |
@@ -33,17 +33,17 @@ |
||
33 | 33 | * @return boolean|string |
34 | 34 | * @throws ValidationException |
35 | 35 | */ |
36 | - public function validate($value, $params = [], $throw = true) |
|
36 | + public function validate($value, $params = [ ], $throw = true) |
|
37 | 37 | { |
38 | - $limit = $params[0]; |
|
38 | + $limit = $params[ 0 ]; |
|
39 | 39 | $length = is_string($value) ? strlen($value) : count($value); |
40 | 40 | |
41 | - if($length >= $limit){ |
|
41 | + if ($length >= $limit) { |
|
42 | 42 | return true; |
43 | 43 | } |
44 | 44 | |
45 | 45 | $message = "Value must be contain %s character at least"; |
46 | - if($throw){ |
|
46 | + if ($throw) { |
|
47 | 47 | throw (new ValidationException($message, $limit)); |
48 | 48 | } |
49 | 49 |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * @return boolean|string |
34 | 34 | * @throws ValidationException |
35 | 35 | */ |
36 | - public function validate($value, $params = [], $throw = true) |
|
36 | + public function validate($value, $params = [ ], $throw = true) |
|
37 | 37 | { |
38 | 38 | if (filter_var($value, FILTER_VALIDATE_URL)) { |
39 | 39 | return true; |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * @return boolean|string |
34 | 34 | * @throws ValidationException |
35 | 35 | */ |
36 | - public function validate($value, $params = [], $throw = true) |
|
36 | + public function validate($value, $params = [ ], $throw = true) |
|
37 | 37 | { |
38 | 38 | if (is_numeric($value) && is_int($value)) { |
39 | 39 | return true; |
@@ -33,15 +33,15 @@ |
||
33 | 33 | * @return boolean|string |
34 | 34 | * @throws ValidationException |
35 | 35 | */ |
36 | - public function validate($value, $params = [], $throw = true) |
|
36 | + public function validate($value, $params = [ ], $throw = true) |
|
37 | 37 | { |
38 | - $cmp = $params[0]; |
|
39 | - if($value > $cmp){ |
|
38 | + $cmp = $params[ 0 ]; |
|
39 | + if ($value > $cmp) { |
|
40 | 40 | return true; |
41 | 41 | } |
42 | 42 | |
43 | 43 | $message = "Value must be greater than %s"; |
44 | - if($throw){ |
|
44 | + if ($throw) { |
|
45 | 45 | throw (new ValidationException($message, $cmp)); |
46 | 46 | } |
47 | 47 |