@@ -27,16 +27,16 @@ discard block |
||
27 | 27 | $this->value = $data; |
28 | 28 | $this->keyPath = $this->buildKey($keyPath); |
29 | 29 | $this->value = $this->recursiveGet($data, $this->keyPath, null); |
30 | - if($validator === null) { |
|
31 | - $validator = function ($data) { |
|
32 | - if(is_array($data)) { |
|
30 | + if ($validator === null) { |
|
31 | + $validator = function($data) { |
|
32 | + if (is_array($data)) { |
|
33 | 33 | return $this->isValidArray($data); |
34 | 34 | } |
35 | 35 | return (string) $data !== ''; |
36 | 36 | }; |
37 | 37 | } |
38 | - if($validationResultHandler === null) { |
|
39 | - $validationResultHandler = static function () {}; |
|
38 | + if ($validationResultHandler === null) { |
|
39 | + $validationResultHandler = static function() {}; |
|
40 | 40 | } |
41 | 41 | $this->validator = $validator; |
42 | 42 | $this->validationResultHandler = $validationResultHandler; |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | * @return string[] |
74 | 74 | */ |
75 | 75 | private function buildKey($keyPath): array { |
76 | - if(is_string($keyPath)) { |
|
76 | + if (is_string($keyPath)) { |
|
77 | 77 | $keyPath = explode('.', $keyPath); |
78 | 78 | } |
79 | - if(!is_array($keyPath)) { |
|
79 | + if (!is_array($keyPath)) { |
|
80 | 80 | throw new RuntimeException('Invalid key'); |
81 | 81 | } |
82 | 82 | return $keyPath; |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @return bool |
88 | 88 | */ |
89 | 89 | private function isValidArray(array $array): bool { |
90 | - $data = array_filter($array, function ($value) { |
|
91 | - if(is_array($value)) { |
|
90 | + $data = array_filter($array, function($value) { |
|
91 | + if (is_array($value)) { |
|
92 | 92 | return $this->isValidArray($value); |
93 | 93 | } |
94 | 94 | return (string) $value !== ''; |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | if (!$count) { |
108 | 108 | return $default; |
109 | 109 | } |
110 | - foreach($path as $idxValue) { |
|
110 | + foreach ($path as $idxValue) { |
|
111 | 111 | $part = $idxValue; |
112 | - if(!array_key_exists($part, $array)) { |
|
112 | + if (!array_key_exists($part, $array)) { |
|
113 | 113 | return $default; |
114 | 114 | } |
115 | 115 | $array = $array[$part]; |
@@ -34,8 +34,8 @@ |
||
34 | 34 | * @return DBExprFilter |
35 | 35 | */ |
36 | 36 | public function __invoke(string $expression, $keyPath, $validator = null) { |
37 | - return new DBExprFilter($expression, $this->map, $keyPath, $validator, static function ($result, array $data) { |
|
38 | - if(!$result) { |
|
37 | + return new DBExprFilter($expression, $this->map, $keyPath, $validator, static function($result, array $data) { |
|
38 | + if (!$result) { |
|
39 | 39 | throw new RequiredValueNotFoundException(sprintf("Required value %s not found", $data['key'])); |
40 | 40 | } |
41 | 41 | }); |
@@ -11,16 +11,16 @@ |
||
11 | 11 | */ |
12 | 12 | public function __construct(array $spec, array $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[] = [ |
@@ -22,17 +22,17 @@ |
||
22 | 22 | * @return Generator|mixed[] |
23 | 23 | */ |
24 | 24 | public function generate(QueryStatement $statement, Closure $callback = null) { |
25 | - while($row = $statement->fetch()) { |
|
26 | - if($this->preserveTypes) { |
|
25 | + while ($row = $statement->fetch()) { |
|
26 | + if ($this->preserveTypes) { |
|
27 | 27 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
28 | 28 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
29 | 29 | } |
30 | - if($callback !== null) { |
|
30 | + if ($callback !== null) { |
|
31 | 31 | $result = $callback($row); |
32 | - if($result instanceof DBIgnoreRow) { |
|
32 | + if ($result instanceof DBIgnoreRow) { |
|
33 | 33 | // Do nothing in this case |
34 | 34 | continue; |
35 | - } elseif($result !== null) { |
|
35 | + } elseif ($result !== null) { |
|
36 | 36 | yield $result; |
37 | 37 | } else { |
38 | 38 | yield $row; |
@@ -10,7 +10,7 @@ |
||
10 | 10 | */ |
11 | 11 | public static function getFieldTypes(QueryStatement $statement): array { |
12 | 12 | $fieldTypes = []; |
13 | - for($i = 0; $column = $statement->getColumnMeta($i); $i++) { |
|
13 | + for ($i = 0; $column = $statement->getColumnMeta($i); $i++) { |
|
14 | 14 | $fieldTypes[$column['name']] = self::getTypeFromNativeType($column['native_type']); |
15 | 15 | } |
16 | 16 | return $fieldTypes; |
@@ -8,8 +8,8 @@ |
||
8 | 8 | * @return array |
9 | 9 | */ |
10 | 10 | public static function convertValues(array $row, array $columnDefinitions): array { |
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 | } |
@@ -13,34 +13,34 @@ |
||
13 | 13 | * @return string |
14 | 14 | */ |
15 | 15 | protected function buildTableName(?string $alias, $name): string { |
16 | - if(is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
16 | + if (is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
17 | 17 | $name = (string) $name; |
18 | 18 | $lines = explode("\n", $name); |
19 | - $lines = array_map(static function (string $line) { return "\t{$line}"; }, $lines); |
|
19 | + $lines = array_map(static function(string $line) { return "\t{$line}"; }, $lines); |
|
20 | 20 | $name = implode("\n", $lines); |
21 | - $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
|
21 | + $name = '('.trim(rtrim(trim($name), ';')).')'; |
|
22 | 22 | } |
23 | - if(is_array($name)) { |
|
23 | + if (is_array($name)) { |
|
24 | 24 | $parts = []; |
25 | - foreach($name as $index => $bucket) { |
|
26 | - if(is_scalar($bucket) && ctype_digit((string) $index)) { |
|
25 | + foreach ($name as $index => $bucket) { |
|
26 | + if (is_scalar($bucket) && ctype_digit((string) $index)) { |
|
27 | 27 | $parts[] = "SELECT {$this->db()->quote($bucket)} AS {$this->db()->quoteField('value')}"; |
28 | 28 | } else { |
29 | 29 | $values = []; |
30 | - foreach($bucket as $field => $value) { |
|
30 | + foreach ($bucket as $field => $value) { |
|
31 | 31 | $values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field)); |
32 | 32 | } |
33 | 33 | $parts[] = sprintf("SELECT %s", implode(', ', $values)); |
34 | 34 | } |
35 | 35 | } |
36 | - $name = '(' . implode("\n\tUNION\n\t", $parts) . ')'; |
|
36 | + $name = '('.implode("\n\tUNION\n\t", $parts).')'; |
|
37 | 37 | } |
38 | - if($this->db()->getVirtualTables()->has($name)) { |
|
38 | + if ($this->db()->getVirtualTables()->has($name)) { |
|
39 | 39 | $select = (string) $this->db()->getVirtualTables()->get($name); |
40 | 40 | $name = sprintf('(%s)', implode("\n\t", explode("\n", trim($select)))); |
41 | 41 | } |
42 | 42 | $name = $this->aliasReplacer()->replace($name); |
43 | - if($alias !== null) { |
|
43 | + if ($alias !== null) { |
|
44 | 44 | return sprintf("%s %s", $name, $alias); |
45 | 45 | } |
46 | 46 | return $name; |
@@ -49,15 +49,15 @@ |
||
49 | 49 | */ |
50 | 50 | protected function buildJoins(string $query): string { |
51 | 51 | $arr = []; |
52 | - foreach($this->joinTables as $table) { |
|
52 | + foreach ($this->joinTables as $table) { |
|
53 | 53 | $join = $table['type']." JOIN\n"; |
54 | - $join .= "\t" . $this->buildTableName($table['alias'], $table['name']); |
|
55 | - if($table['expression']) { |
|
56 | - $join .= " ON " . $this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
54 | + $join .= "\t".$this->buildTableName($table['alias'], $table['name']); |
|
55 | + if ($table['expression']) { |
|
56 | + $join .= " ON ".$this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
57 | 57 | } |
58 | 58 | $arr[] = $join; |
59 | 59 | } |
60 | - if(count($arr)) { |
|
60 | + if (count($arr)) { |
|
61 | 61 | $query .= implode("\n", $arr)."\n"; |
62 | 62 | } |
63 | 63 | return $query; |
@@ -28,10 +28,10 @@ |
||
28 | 28 | */ |
29 | 29 | protected function buildLimit(string $query, ?int $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; |