@@ -13,7 +13,6 @@ |
||
13 | 13 | use Doctrine\ORM\QueryBuilder; |
14 | 14 | use RDS\Hydrogen\Criteria\CriterionInterface; |
15 | 15 | use RDS\Hydrogen\Criteria\Relation; |
16 | -use RDS\Hydrogen\Query; |
|
17 | 16 | |
18 | 17 | /** |
19 | 18 | * Class RelationBuilder |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $builder->addSelect("RAW('$table', '$alias', '$parent') AS $parent"); |
43 | 43 | } |
44 | 44 | |
45 | - yield function (iterable $result) use ($association, $selections, $relation) { |
|
45 | + yield function(iterable $result) use ($association, $selections, $relation) { |
|
46 | 46 | $query = $relation->getQuery(); |
47 | 47 | [$table, $alias] = [$this->meta($association['targetEntity'])->getTableName(), $query->getAlias()]; |
48 | 48 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | foreach ($selections as $parent => ['relatedTo' => $child, 'values' => $values]) { |
56 | 56 | $query->select(["RAW('$table', '$alias', '$child')" => $child]); |
57 | - $query = $query->whereIn(':' . $child, $values); |
|
57 | + $query = $query->whereIn(':'.$child, $values); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $this->execute($association['targetEntity'], $query); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | { |
71 | 71 | $association = $metadata->associationMappings[$relation] ?? null; |
72 | 72 | |
73 | - if (! $association) { |
|
73 | + if (!$association) { |
|
74 | 74 | $error = 'Invalid relation name "%s" of entity %s'; |
75 | 75 | throw new \LogicException(\sprintf($error, $relation, $metadata->name)); |
76 | 76 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | { |
98 | 98 | $joins = $association['joinColumns'] ?? null; |
99 | 99 | |
100 | - if (! $joins) { |
|
100 | + if (!$joins) { |
|
101 | 101 | $error = 'Relation "%s" of entity %s should provide one or more join columns.'; |
102 | 102 | throw new \LogicException(\sprintf($error, $association['fieldName'], $association['sourceEntity'])); |
103 | 103 | } |
@@ -10,9 +10,7 @@ |
||
10 | 10 | namespace RDS\Hydrogen; |
11 | 11 | |
12 | 12 | use Doctrine\Common\Persistence\ObjectRepository; |
13 | -use Doctrine\ORM\EntityManagerInterface; |
|
14 | 13 | use Illuminate\Support\Traits\Macroable; |
15 | -use phpDocumentor\Reflection\Types\Self_; |
|
16 | 14 | use RDS\Hydrogen\Criteria\CriterionInterface; |
17 | 15 | use RDS\Hydrogen\Fn\RawFunction; |
18 | 16 | use RDS\Hydrogen\Query\AliasProvider; |
@@ -81,7 +81,7 @@ |
||
81 | 81 | |
82 | 82 | $config = $this->getRepository()->getEntityManager()->getConfiguration(); |
83 | 83 | |
84 | - if (! $config->getCustomStringFunction('RAW')) { |
|
84 | + if (!$config->getCustomStringFunction('RAW')) { |
|
85 | 85 | $config->addCustomStringFunction('RAW', RawFunction::class); |
86 | 86 | } |
87 | 87 | } |
@@ -21,6 +21,7 @@ discard block |
||
21 | 21 | { |
22 | 22 | /** |
23 | 23 | * @param string ...$fields |
24 | + * @param string[] $fields |
|
24 | 25 | * @return object[]|iterable |
25 | 26 | */ |
26 | 27 | public function get(string ...$fields): iterable |
@@ -167,6 +168,7 @@ discard block |
||
167 | 168 | |
168 | 169 | /** |
169 | 170 | * @param string ...$fields |
171 | + * @param string[] $fields |
|
170 | 172 | * @return Collection |
171 | 173 | */ |
172 | 174 | public function collect(string ...$fields): Collection |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $processor = $this->getRepository()->getProcessor(); |
29 | 29 | |
30 | 30 | if (\count($fields)) { |
31 | - return \collect($processor->getArrayResult($this))->map(function (array $data) use ($fields) { |
|
31 | + return \collect($processor->getArrayResult($this))->map(function(array $data) use ($fields) { |
|
32 | 32 | if (isset($data[0]) && \is_array($data[0])) { |
33 | 33 | $data = $data[0]; |
34 | 34 | } |
@@ -89,22 +89,22 @@ discard block |
||
89 | 89 | |
90 | 90 | switch ($typeOf) { |
91 | 91 | case 'callable': |
92 | - return function (callable $applicator = null) use ($result) { |
|
92 | + return function(callable $applicator = null) use ($result) { |
|
93 | 93 | return ($applicator ?? '\\value')($result); |
94 | 94 | }; |
95 | 95 | |
96 | 96 | case 'object': |
97 | - return (object)$result; |
|
97 | + return (object) $result; |
|
98 | 98 | |
99 | 99 | case 'array': |
100 | 100 | case 'iterable': |
101 | - return (array)$result; |
|
101 | + return (array) $result; |
|
102 | 102 | } |
103 | 103 | |
104 | - $function = $typeOf . 'val'; |
|
104 | + $function = $typeOf.'val'; |
|
105 | 105 | |
106 | - if (! \function_exists($function)) { |
|
107 | - throw new \InvalidArgumentException('Could not cast to type ' . $typeOf); |
|
106 | + if (!\function_exists($function)) { |
|
107 | + throw new \InvalidArgumentException('Could not cast to type '.$typeOf); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | return $function($result); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function count(?string $field = 'id'): int |
119 | 119 | { |
120 | - return $this->select('COUNT(' . $field . ') AS __count') |
|
120 | + return $this->select('COUNT('.$field.') AS __count') |
|
121 | 121 | ->scalar('__count', 'int'); |
122 | 122 | } |
123 | 123 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function sum(string $field = null): int |
130 | 130 | { |
131 | - return $this->select('SUM(' . $field . ') AS __sum') |
|
131 | + return $this->select('SUM('.$field.') AS __sum') |
|
132 | 132 | ->scalar('__sum', 'int'); |
133 | 133 | } |
134 | 134 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function avg(string $field = null): int |
141 | 141 | { |
142 | - return $this->select('AVG(' . $field . ') AS __avg') |
|
142 | + return $this->select('AVG('.$field.') AS __avg') |
|
143 | 143 | ->scalar('__avg', 'int'); |
144 | 144 | } |
145 | 145 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public function max(string $field = null): int |
152 | 152 | { |
153 | - return $this->select('MAX(' . $field . ') AS __max') |
|
153 | + return $this->select('MAX('.$field.') AS __max') |
|
154 | 154 | ->scalar('__max', 'int'); |
155 | 155 | } |
156 | 156 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function min(string $field = null): int |
163 | 163 | { |
164 | - return $this->select('MIN(' . $field . ') AS __min') |
|
164 | + return $this->select('MIN('.$field.') AS __min') |
|
165 | 165 | ->scalar('__min', 'int'); |
166 | 166 | } |
167 | 167 |
@@ -58,6 +58,6 @@ |
||
58 | 58 | { |
59 | 59 | $alias = $sqlWalker->getSQLTableAlias($this->table->value, $this->alias->value); |
60 | 60 | |
61 | - return $alias . '.' . $this->field->value; |
|
61 | + return $alias.'.'.$this->field->value; |
|
62 | 62 | } |
63 | 63 | } |
@@ -72,16 +72,16 @@ |
||
72 | 72 | \preg_match('/^([\w\.\:\*]+)[\w\.\:\*\s]*?$/iu', $query, $m); |
73 | 73 | if (\count($m)) { |
74 | 74 | $wrapper = [\str_replace_first($m[1], '%s', $m[0])]; |
75 | - return \array_merge($wrapper, $this->analyzePrefix((string)$m[1])); |
|
75 | + return \array_merge($wrapper, $this->analyzePrefix((string) $m[1])); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | \preg_match('/^.+?\(([\w\.\:\*]+).*?$/isu', $query, $m); |
79 | 79 | if (\count($m)) { |
80 | 80 | $wrapper = [\str_replace_first($m[1], '%s', $m[0])]; |
81 | - return \array_merge($wrapper, $this->analyzePrefix((string)$m[1])); |
|
81 | + return \array_merge($wrapper, $this->analyzePrefix((string) $m[1])); |
|
82 | 82 | } |
83 | 83 | |
84 | - return ['%s', (string)$query, false]; |
|
84 | + return ['%s', (string) $query, false]; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -70,7 +70,7 @@ |
||
70 | 70 | private function extract(iterable $result): \Generator |
71 | 71 | { |
72 | 72 | foreach ($result as $item) { |
73 | - if (isset($item[0]) && ! \is_scalar($item[0])) { |
|
73 | + if (isset($item[0]) && !\is_scalar($item[0])) { |
|
74 | 74 | $entity = \array_shift($item); |
75 | 75 | yield $entity => $item; |
76 | 76 | } else { |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function getScalarResult(Query $query) |
58 | 58 | { |
59 | - return $this->exec($query, function (DoctrineQuery $query) { |
|
59 | + return $this->exec($query, function(DoctrineQuery $query) { |
|
60 | 60 | return $query->getSingleScalarResult(); |
61 | 61 | }); |
62 | 62 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | */ |
158 | 158 | private function applicator(QueryBuilder $builder): \Closure |
159 | 159 | { |
160 | - return function ($response) use ($builder) { |
|
160 | + return function($response) use ($builder) { |
|
161 | 161 | // Send the context (the builder) in case the |
162 | 162 | // answer contains an empty value. |
163 | 163 | if ($response === null) { |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function getResult(Query $query): iterable |
185 | 185 | { |
186 | - $result = $this->exec($query, function (DoctrineQuery $query) { |
|
186 | + $result = $this->exec($query, function(DoctrineQuery $query) { |
|
187 | 187 | return $query->getResult(); |
188 | 188 | }); |
189 | 189 | |
190 | - $fn = function (array $result) { |
|
190 | + $fn = function(array $result) { |
|
191 | 191 | foreach ($result as $item) { |
192 | 192 | yield \is_array($item) ? \reset($item) : $item; |
193 | 193 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | */ |
203 | 203 | public function getArrayResult(Query $query): array |
204 | 204 | { |
205 | - return $this->exec($query, function (DoctrineQuery $query) { |
|
205 | + return $this->exec($query, function(DoctrineQuery $query) { |
|
206 | 206 | return $query->getArrayResult(); |
207 | 207 | }); |
208 | 208 | } |