@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | UriFactoryInterface $uriFactory, |
78 | 78 | StreamFactoryInterface $streamFactory, |
79 | 79 | UploadedFileFactoryInterface $uploadedFileFactory |
80 | - ) { |
|
80 | + ){ |
|
81 | 81 | $this->requestFactory = $requestFactory; |
82 | 82 | $this->uriFactory = $uriFactory; |
83 | 83 | $this->streamFactory = $streamFactory; |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | $uri = $this->getUri($server); |
125 | 125 | |
126 | 126 | $request = $this->requestFactory->createServerRequest($method, $uri, $server); |
127 | - foreach ($headers as $name => $value) { |
|
127 | + foreach ($headers as $name => $value){ |
|
128 | 128 | $request = $request->withAddedHeader($name, $value); |
129 | 129 | } |
130 | 130 | |
131 | 131 | $protocol = '1.1'; |
132 | - if (!empty($_SERVER['SERVER_PROTOCOL'])) { |
|
132 | + if (!empty($_SERVER['SERVER_PROTOCOL'])){ |
|
133 | 133 | $protocol = str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']); |
134 | 134 | } |
135 | 135 | |
@@ -140,15 +140,15 @@ discard block |
||
140 | 140 | ->withCookieParams($cookies) |
141 | 141 | ->withUploadedFiles($this->getUploadedFilesArray($files)); |
142 | 142 | |
143 | - if ($body === null) { |
|
143 | + if ($body === null){ |
|
144 | 144 | return $request; |
145 | 145 | } |
146 | 146 | |
147 | - if (\is_resource($body)) { |
|
147 | + if (\is_resource($body)){ |
|
148 | 148 | $body = $this->streamFactory->createStreamFromResource($body); |
149 | - } elseif (\is_string($body)) { |
|
149 | + } elseif (\is_string($body)){ |
|
150 | 150 | $body = $this->streamFactory->createStream($body); |
151 | - } elseif (!$body instanceof StreamInterface) { |
|
151 | + } elseif (!$body instanceof StreamInterface){ |
|
152 | 152 | throw new \InvalidArgumentException( |
153 | 153 | 'Body parameter for ServerRequestFactory::createFromParameters() ' |
154 | 154 | . 'must be instance of StreamInterface, resource or null.' |
@@ -165,29 +165,29 @@ discard block |
||
165 | 165 | private function getUri(array $server): UriInterface |
166 | 166 | { |
167 | 167 | $uri = $this->uriFactory->createUri(); |
168 | - if (isset($server['HTTPS'])) { |
|
168 | + if (isset($server['HTTPS'])){ |
|
169 | 169 | $uri = $uri->withScheme($server['HTTPS'] === 'on' ? 'https' : 'http'); |
170 | 170 | } |
171 | 171 | |
172 | - if (isset($server['HTTP_HOST'])) { |
|
173 | - if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) { |
|
172 | + if (isset($server['HTTP_HOST'])){ |
|
173 | + if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)){ |
|
174 | 174 | $uri = $uri->withHost($matches[1])->withPort($matches[2]); |
175 | - } else { |
|
175 | + }else{ |
|
176 | 176 | $uri = $uri->withHost($server['HTTP_HOST']); |
177 | 177 | } |
178 | - } elseif (isset($server['SERVER_NAME'])) { |
|
178 | + } elseif (isset($server['SERVER_NAME'])){ |
|
179 | 179 | $uri = $uri->withHost($server['SERVER_NAME']); |
180 | 180 | } |
181 | 181 | |
182 | - if (isset($server['SERVER_PORT'])) { |
|
182 | + if (isset($server['SERVER_PORT'])){ |
|
183 | 183 | $uri = $uri->withPort($server['SERVER_PORT']); |
184 | 184 | } |
185 | 185 | |
186 | - if (isset($server['REQUEST_URI'])) { |
|
186 | + if (isset($server['REQUEST_URI'])){ |
|
187 | 187 | $uri = $uri->withPath(\explode('?', $server['REQUEST_URI'])[0]); |
188 | 188 | } |
189 | 189 | |
190 | - if (isset($server['QUERY_STRING'])) { |
|
190 | + if (isset($server['QUERY_STRING'])){ |
|
191 | 191 | $uri = $uri->withQuery($server['QUERY_STRING']); |
192 | 192 | } |
193 | 193 | |
@@ -199,12 +199,12 @@ discard block |
||
199 | 199 | */ |
200 | 200 | private static function getHeadersFromGlobals(): array |
201 | 201 | { |
202 | - if (\function_exists('getallheaders')) { |
|
202 | + if (\function_exists('getallheaders')){ |
|
203 | 203 | $headers = getallheaders(); |
204 | - } else { |
|
204 | + }else{ |
|
205 | 205 | $headers = []; |
206 | - foreach ($_SERVER as $name => $value) { |
|
207 | - if (strncmp($name, 'HTTP_', 5) === 0) { |
|
206 | + foreach ($_SERVER as $name => $value){ |
|
207 | + if (strncmp($name, 'HTTP_', 5) === 0){ |
|
208 | 208 | $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); |
209 | 209 | $headers[$name] = $value; |
210 | 210 | } |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | private function getUploadedFilesArray(array $filesArray): array |
222 | 222 | { |
223 | 223 | $files = []; |
224 | - foreach ($filesArray as $class => $info) { |
|
224 | + foreach ($filesArray as $class => $info){ |
|
225 | 225 | $files[$class] = []; |
226 | 226 | $this->populateUploadedFileRecursive( |
227 | 227 | $files[$class], |
@@ -249,8 +249,8 @@ discard block |
||
249 | 249 | */ |
250 | 250 | private function populateUploadedFileRecursive(&$files, $names, $tempNames, $types, $sizes, $errors): void |
251 | 251 | { |
252 | - if (\is_array($names)) { |
|
253 | - foreach ($names as $i => $name) { |
|
252 | + if (\is_array($names)){ |
|
253 | + foreach ($names as $i => $name){ |
|
254 | 254 | $files[$i] = []; |
255 | 255 | $this->populateUploadedFileRecursive( |
256 | 256 | $files[$i], |
@@ -261,10 +261,10 @@ discard block |
||
261 | 261 | $errors[$i] |
262 | 262 | ); |
263 | 263 | } |
264 | - } else { |
|
265 | - try { |
|
264 | + }else{ |
|
265 | + try{ |
|
266 | 266 | $stream = $this->streamFactory->createStreamFromFile($tempNames); |
267 | - } catch (\RuntimeException $e) { |
|
267 | + }catch (\RuntimeException $e){ |
|
268 | 268 | $stream = $this->streamFactory->createStream(); |
269 | 269 | } |
270 | 270 |
@@ -124,12 +124,14 @@ discard block |
||
124 | 124 | $uri = $this->getUri($server); |
125 | 125 | |
126 | 126 | $request = $this->requestFactory->createServerRequest($method, $uri, $server); |
127 | - foreach ($headers as $name => $value) { |
|
127 | + foreach ($headers as $name => $value) |
|
128 | + { |
|
128 | 129 | $request = $request->withAddedHeader($name, $value); |
129 | 130 | } |
130 | 131 | |
131 | 132 | $protocol = '1.1'; |
132 | - if (!empty($_SERVER['SERVER_PROTOCOL'])) { |
|
133 | + if (!empty($_SERVER['SERVER_PROTOCOL'])) |
|
134 | + { |
|
133 | 135 | $protocol = str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']); |
134 | 136 | } |
135 | 137 | |
@@ -140,15 +142,21 @@ discard block |
||
140 | 142 | ->withCookieParams($cookies) |
141 | 143 | ->withUploadedFiles($this->getUploadedFilesArray($files)); |
142 | 144 | |
143 | - if ($body === null) { |
|
145 | + if ($body === null) |
|
146 | + { |
|
144 | 147 | return $request; |
145 | 148 | } |
146 | 149 | |
147 | - if (\is_resource($body)) { |
|
150 | + if (\is_resource($body)) |
|
151 | + { |
|
148 | 152 | $body = $this->streamFactory->createStreamFromResource($body); |
149 | - } elseif (\is_string($body)) { |
|
153 | + } |
|
154 | + elseif (\is_string($body)) |
|
155 | + { |
|
150 | 156 | $body = $this->streamFactory->createStream($body); |
151 | - } elseif (!$body instanceof StreamInterface) { |
|
157 | + } |
|
158 | + elseif (!$body instanceof StreamInterface) |
|
159 | + { |
|
152 | 160 | throw new \InvalidArgumentException( |
153 | 161 | 'Body parameter for ServerRequestFactory::createFromParameters() ' |
154 | 162 | . 'must be instance of StreamInterface, resource or null.' |
@@ -165,29 +173,39 @@ discard block |
||
165 | 173 | private function getUri(array $server): UriInterface |
166 | 174 | { |
167 | 175 | $uri = $this->uriFactory->createUri(); |
168 | - if (isset($server['HTTPS'])) { |
|
176 | + if (isset($server['HTTPS'])) |
|
177 | + { |
|
169 | 178 | $uri = $uri->withScheme($server['HTTPS'] === 'on' ? 'https' : 'http'); |
170 | 179 | } |
171 | 180 | |
172 | - if (isset($server['HTTP_HOST'])) { |
|
173 | - if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) { |
|
181 | + if (isset($server['HTTP_HOST'])) |
|
182 | + { |
|
183 | + if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) |
|
184 | + { |
|
174 | 185 | $uri = $uri->withHost($matches[1])->withPort($matches[2]); |
175 | - } else { |
|
186 | + } |
|
187 | + else |
|
188 | + { |
|
176 | 189 | $uri = $uri->withHost($server['HTTP_HOST']); |
177 | 190 | } |
178 | - } elseif (isset($server['SERVER_NAME'])) { |
|
191 | + } |
|
192 | + elseif (isset($server['SERVER_NAME'])) |
|
193 | + { |
|
179 | 194 | $uri = $uri->withHost($server['SERVER_NAME']); |
180 | 195 | } |
181 | 196 | |
182 | - if (isset($server['SERVER_PORT'])) { |
|
197 | + if (isset($server['SERVER_PORT'])) |
|
198 | + { |
|
183 | 199 | $uri = $uri->withPort($server['SERVER_PORT']); |
184 | 200 | } |
185 | 201 | |
186 | - if (isset($server['REQUEST_URI'])) { |
|
202 | + if (isset($server['REQUEST_URI'])) |
|
203 | + { |
|
187 | 204 | $uri = $uri->withPath(\explode('?', $server['REQUEST_URI'])[0]); |
188 | 205 | } |
189 | 206 | |
190 | - if (isset($server['QUERY_STRING'])) { |
|
207 | + if (isset($server['QUERY_STRING'])) |
|
208 | + { |
|
191 | 209 | $uri = $uri->withQuery($server['QUERY_STRING']); |
192 | 210 | } |
193 | 211 | |
@@ -199,12 +217,17 @@ discard block |
||
199 | 217 | */ |
200 | 218 | private static function getHeadersFromGlobals(): array |
201 | 219 | { |
202 | - if (\function_exists('getallheaders')) { |
|
220 | + if (\function_exists('getallheaders')) |
|
221 | + { |
|
203 | 222 | $headers = getallheaders(); |
204 | - } else { |
|
223 | + } |
|
224 | + else |
|
225 | + { |
|
205 | 226 | $headers = []; |
206 | - foreach ($_SERVER as $name => $value) { |
|
207 | - if (strncmp($name, 'HTTP_', 5) === 0) { |
|
227 | + foreach ($_SERVER as $name => $value) |
|
228 | + { |
|
229 | + if (strncmp($name, 'HTTP_', 5) === 0) |
|
230 | + { |
|
208 | 231 | $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); |
209 | 232 | $headers[$name] = $value; |
210 | 233 | } |
@@ -221,7 +244,8 @@ discard block |
||
221 | 244 | private function getUploadedFilesArray(array $filesArray): array |
222 | 245 | { |
223 | 246 | $files = []; |
224 | - foreach ($filesArray as $class => $info) { |
|
247 | + foreach ($filesArray as $class => $info) |
|
248 | + { |
|
225 | 249 | $files[$class] = []; |
226 | 250 | $this->populateUploadedFileRecursive( |
227 | 251 | $files[$class], |
@@ -249,8 +273,10 @@ discard block |
||
249 | 273 | */ |
250 | 274 | private function populateUploadedFileRecursive(&$files, $names, $tempNames, $types, $sizes, $errors): void |
251 | 275 | { |
252 | - if (\is_array($names)) { |
|
253 | - foreach ($names as $i => $name) { |
|
276 | + if (\is_array($names)) |
|
277 | + { |
|
278 | + foreach ($names as $i => $name) |
|
279 | + { |
|
254 | 280 | $files[$i] = []; |
255 | 281 | $this->populateUploadedFileRecursive( |
256 | 282 | $files[$i], |
@@ -261,10 +287,15 @@ discard block |
||
261 | 287 | $errors[$i] |
262 | 288 | ); |
263 | 289 | } |
264 | - } else { |
|
265 | - try { |
|
290 | + } |
|
291 | + else |
|
292 | + { |
|
293 | + try |
|
294 | + { |
|
266 | 295 | $stream = $this->streamFactory->createStreamFromFile($tempNames); |
267 | - } catch (\RuntimeException $e) { |
|
296 | + } |
|
297 | + catch (\RuntimeException $e) |
|
298 | + { |
|
268 | 299 | $stream = $this->streamFactory->createStream(); |
269 | 300 | } |
270 | 301 |
@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function leaveNode(Node $node) |
44 | 44 | { |
45 | - if (!$node instanceof Node\Stmt\Class_) { |
|
45 | + if (!$node instanceof Node\Stmt\Class_){ |
|
46 | 46 | return null; |
47 | 47 | } |
48 | 48 | |
49 | 49 | $constructor = $this->getConstructorAttribute($node); |
50 | 50 | $this->addDependencies($constructor); |
51 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
51 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams){ |
|
52 | 52 | $this->addParentConstructorCall($constructor); |
53 | 53 | } |
54 | 54 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
68 | 68 | { |
69 | - foreach ($this->definition->dependencies as $dependency) { |
|
69 | + foreach ($this->definition->dependencies as $dependency){ |
|
70 | 70 | $constructor->params[] = (new Param($dependency->var))->setType( |
71 | 71 | new Node\Name($this->getPropertyType($dependency)) |
72 | 72 | )->getNode(); |
@@ -91,34 +91,34 @@ discard block |
||
91 | 91 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
92 | 92 | { |
93 | 93 | $parentConstructorDependencies = []; |
94 | - foreach ($this->definition->constructorParams as $param) { |
|
94 | + foreach ($this->definition->constructorParams as $param){ |
|
95 | 95 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
96 | 96 | |
97 | 97 | $cp = new Param($param->name); |
98 | - if (!empty($param->type)) { |
|
98 | + if (!empty($param->type)){ |
|
99 | 99 | $type = $this->getParamType($param); |
100 | - if ($param->nullable) { |
|
100 | + if ($param->nullable){ |
|
101 | 101 | $type = "?$type"; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $cp->setType(new Node\Name($type)); |
105 | 105 | } |
106 | 106 | |
107 | - if ($param->byRef) { |
|
107 | + if ($param->byRef){ |
|
108 | 108 | $cp->makeByRef(); |
109 | 109 | } |
110 | 110 | |
111 | - if ($param->isVariadic) { |
|
111 | + if ($param->isVariadic){ |
|
112 | 112 | $cp->makeVariadic(); |
113 | 113 | } |
114 | 114 | |
115 | - if ($param->hasDefault) { |
|
115 | + if ($param->hasDefault){ |
|
116 | 116 | $cp->setDefault($param->default); |
117 | 117 | } |
118 | 118 | $constructor->params[] = $cp->getNode(); |
119 | 119 | } |
120 | 120 | |
121 | - if ($parentConstructorDependencies) { |
|
121 | + if ($parentConstructorDependencies){ |
|
122 | 122 | array_unshift( |
123 | 123 | $constructor->stmts, |
124 | 124 | new Node\Stmt\Expression( |
@@ -153,18 +153,18 @@ discard block |
||
153 | 153 | |
154 | 154 | $params = []; |
155 | 155 | |
156 | - foreach ($this->definition->dependencies as $dependency) { |
|
156 | + foreach ($this->definition->dependencies as $dependency){ |
|
157 | 157 | $params[] = new Annotation\Line( |
158 | 158 | sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), |
159 | 159 | 'param' |
160 | 160 | ); |
161 | 161 | } |
162 | 162 | |
163 | - if (!$this->definition->hasConstructor) { |
|
164 | - foreach ($this->definition->constructorParams as $param) { |
|
165 | - if (!empty($param->type)) { |
|
163 | + if (!$this->definition->hasConstructor){ |
|
164 | + foreach ($this->definition->constructorParams as $param){ |
|
165 | + if (!empty($param->type)){ |
|
166 | 166 | $type = $this->getParamType($param); |
167 | - if ($param->nullable) { |
|
167 | + if ($param->nullable){ |
|
168 | 168 | $type = "$type|null"; |
169 | 169 | } |
170 | 170 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), |
173 | 173 | 'param' |
174 | 174 | ); |
175 | - } else { |
|
175 | + }else{ |
|
176 | 176 | $params[] = new Annotation\Line( |
177 | 177 | sprintf('$%s', $param->name), |
178 | 178 | 'param' |
@@ -183,12 +183,12 @@ discard block |
||
183 | 183 | |
184 | 184 | $placementID = 0; |
185 | 185 | $previous = null; |
186 | - foreach ($an->lines as $index => $line) { |
|
186 | + foreach ($an->lines as $index => $line){ |
|
187 | 187 | // always next node |
188 | 188 | $placementID = $index + 1; |
189 | 189 | |
190 | 190 | // inject before this parameters |
191 | - if ($line->is(['throws', 'return'])) { |
|
191 | + if ($line->is(['throws', 'return'])){ |
|
192 | 192 | // insert before given node |
193 | 193 | $placementID--; |
194 | 194 | break; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $previous = $line; |
198 | 198 | } |
199 | 199 | |
200 | - if ($previous !== null && !$previous->isEmpty()) { |
|
200 | + if ($previous !== null && !$previous->isEmpty()){ |
|
201 | 201 | $placementID++; |
202 | 202 | } |
203 | 203 | |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | */ |
213 | 213 | private function getPropertyType(Dependency $dependency): string |
214 | 214 | { |
215 | - foreach ($this->definition->getStmts() as $stmt) { |
|
216 | - if ($stmt->name === $dependency->type->fullName) { |
|
217 | - if ($stmt->alias) { |
|
215 | + foreach ($this->definition->getStmts() as $stmt){ |
|
216 | + if ($stmt->name === $dependency->type->fullName){ |
|
217 | + if ($stmt->alias){ |
|
218 | 218 | return $stmt->alias; |
219 | 219 | } |
220 | 220 | } |
@@ -229,15 +229,15 @@ discard block |
||
229 | 229 | */ |
230 | 230 | private function getParamType(ClassNode\ConstructorParam $param): string |
231 | 231 | { |
232 | - foreach ($this->definition->getStmts() as $stmt) { |
|
233 | - if ($stmt->name === $param->type->fullName) { |
|
234 | - if ($stmt->alias) { |
|
232 | + foreach ($this->definition->getStmts() as $stmt){ |
|
233 | + if ($stmt->name === $param->type->fullName){ |
|
234 | + if ($stmt->alias){ |
|
235 | 235 | return $stmt->alias; |
236 | 236 | } |
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | - if ($param->type->alias) { |
|
240 | + if ($param->type->alias){ |
|
241 | 241 | return $param->type->alias; |
242 | 242 | } |
243 | 243 |
@@ -42,13 +42,15 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function leaveNode(Node $node) |
44 | 44 | { |
45 | - if (!$node instanceof Node\Stmt\Class_) { |
|
45 | + if (!$node instanceof Node\Stmt\Class_) |
|
46 | + { |
|
46 | 47 | return null; |
47 | 48 | } |
48 | 49 | |
49 | 50 | $constructor = $this->getConstructorAttribute($node); |
50 | 51 | $this->addDependencies($constructor); |
51 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
52 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams) |
|
53 | + { |
|
52 | 54 | $this->addParentConstructorCall($constructor); |
53 | 55 | } |
54 | 56 | |
@@ -66,7 +68,8 @@ discard block |
||
66 | 68 | */ |
67 | 69 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
68 | 70 | { |
69 | - foreach ($this->definition->dependencies as $dependency) { |
|
71 | + foreach ($this->definition->dependencies as $dependency) |
|
72 | + { |
|
70 | 73 | $constructor->params[] = (new Param($dependency->var))->setType( |
71 | 74 | new Node\Name($this->getPropertyType($dependency)) |
72 | 75 | )->getNode(); |
@@ -91,34 +94,41 @@ discard block |
||
91 | 94 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
92 | 95 | { |
93 | 96 | $parentConstructorDependencies = []; |
94 | - foreach ($this->definition->constructorParams as $param) { |
|
97 | + foreach ($this->definition->constructorParams as $param) |
|
98 | + { |
|
95 | 99 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
96 | 100 | |
97 | 101 | $cp = new Param($param->name); |
98 | - if (!empty($param->type)) { |
|
102 | + if (!empty($param->type)) |
|
103 | + { |
|
99 | 104 | $type = $this->getParamType($param); |
100 | - if ($param->nullable) { |
|
105 | + if ($param->nullable) |
|
106 | + { |
|
101 | 107 | $type = "?$type"; |
102 | 108 | } |
103 | 109 | |
104 | 110 | $cp->setType(new Node\Name($type)); |
105 | 111 | } |
106 | 112 | |
107 | - if ($param->byRef) { |
|
113 | + if ($param->byRef) |
|
114 | + { |
|
108 | 115 | $cp->makeByRef(); |
109 | 116 | } |
110 | 117 | |
111 | - if ($param->isVariadic) { |
|
118 | + if ($param->isVariadic) |
|
119 | + { |
|
112 | 120 | $cp->makeVariadic(); |
113 | 121 | } |
114 | 122 | |
115 | - if ($param->hasDefault) { |
|
123 | + if ($param->hasDefault) |
|
124 | + { |
|
116 | 125 | $cp->setDefault($param->default); |
117 | 126 | } |
118 | 127 | $constructor->params[] = $cp->getNode(); |
119 | 128 | } |
120 | 129 | |
121 | - if ($parentConstructorDependencies) { |
|
130 | + if ($parentConstructorDependencies) |
|
131 | + { |
|
122 | 132 | array_unshift( |
123 | 133 | $constructor->stmts, |
124 | 134 | new Node\Stmt\Expression( |
@@ -153,18 +163,23 @@ discard block |
||
153 | 163 | |
154 | 164 | $params = []; |
155 | 165 | |
156 | - foreach ($this->definition->dependencies as $dependency) { |
|
166 | + foreach ($this->definition->dependencies as $dependency) |
|
167 | + { |
|
157 | 168 | $params[] = new Annotation\Line( |
158 | 169 | sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), |
159 | 170 | 'param' |
160 | 171 | ); |
161 | 172 | } |
162 | 173 | |
163 | - if (!$this->definition->hasConstructor) { |
|
164 | - foreach ($this->definition->constructorParams as $param) { |
|
165 | - if (!empty($param->type)) { |
|
174 | + if (!$this->definition->hasConstructor) |
|
175 | + { |
|
176 | + foreach ($this->definition->constructorParams as $param) |
|
177 | + { |
|
178 | + if (!empty($param->type)) |
|
179 | + { |
|
166 | 180 | $type = $this->getParamType($param); |
167 | - if ($param->nullable) { |
|
181 | + if ($param->nullable) |
|
182 | + { |
|
168 | 183 | $type = "$type|null"; |
169 | 184 | } |
170 | 185 | |
@@ -172,7 +187,9 @@ discard block |
||
172 | 187 | sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), |
173 | 188 | 'param' |
174 | 189 | ); |
175 | - } else { |
|
190 | + } |
|
191 | + else |
|
192 | + { |
|
176 | 193 | $params[] = new Annotation\Line( |
177 | 194 | sprintf('$%s', $param->name), |
178 | 195 | 'param' |
@@ -183,12 +200,14 @@ discard block |
||
183 | 200 | |
184 | 201 | $placementID = 0; |
185 | 202 | $previous = null; |
186 | - foreach ($an->lines as $index => $line) { |
|
203 | + foreach ($an->lines as $index => $line) |
|
204 | + { |
|
187 | 205 | // always next node |
188 | 206 | $placementID = $index + 1; |
189 | 207 | |
190 | 208 | // inject before this parameters |
191 | - if ($line->is(['throws', 'return'])) { |
|
209 | + if ($line->is(['throws', 'return'])) |
|
210 | + { |
|
192 | 211 | // insert before given node |
193 | 212 | $placementID--; |
194 | 213 | break; |
@@ -197,7 +216,8 @@ discard block |
||
197 | 216 | $previous = $line; |
198 | 217 | } |
199 | 218 | |
200 | - if ($previous !== null && !$previous->isEmpty()) { |
|
219 | + if ($previous !== null && !$previous->isEmpty()) |
|
220 | + { |
|
201 | 221 | $placementID++; |
202 | 222 | } |
203 | 223 | |
@@ -212,9 +232,12 @@ discard block |
||
212 | 232 | */ |
213 | 233 | private function getPropertyType(Dependency $dependency): string |
214 | 234 | { |
215 | - foreach ($this->definition->getStmts() as $stmt) { |
|
216 | - if ($stmt->name === $dependency->type->fullName) { |
|
217 | - if ($stmt->alias) { |
|
235 | + foreach ($this->definition->getStmts() as $stmt) |
|
236 | + { |
|
237 | + if ($stmt->name === $dependency->type->fullName) |
|
238 | + { |
|
239 | + if ($stmt->alias) |
|
240 | + { |
|
218 | 241 | return $stmt->alias; |
219 | 242 | } |
220 | 243 | } |
@@ -229,15 +252,19 @@ discard block |
||
229 | 252 | */ |
230 | 253 | private function getParamType(ClassNode\ConstructorParam $param): string |
231 | 254 | { |
232 | - foreach ($this->definition->getStmts() as $stmt) { |
|
233 | - if ($stmt->name === $param->type->fullName) { |
|
234 | - if ($stmt->alias) { |
|
255 | + foreach ($this->definition->getStmts() as $stmt) |
|
256 | + { |
|
257 | + if ($stmt->name === $param->type->fullName) |
|
258 | + { |
|
259 | + if ($stmt->alias) |
|
260 | + { |
|
235 | 261 | return $stmt->alias; |
236 | 262 | } |
237 | 263 | } |
238 | 264 | } |
239 | 265 | |
240 | - if ($param->type->alias) { |
|
266 | + if ($param->type->alias) |
|
267 | + { |
|
241 | 268 | return $param->type->alias; |
242 | 269 | } |
243 | 270 |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | |
40 | 40 | public function __construct($name = null, array $data = [], $dataName = '') |
41 | 41 | { |
42 | - $this->storage = new Storage($this->dir() . '/Fixtures/'); |
|
42 | + $this->storage = new Storage($this->dir().'/Fixtures/'); |
|
43 | 43 | parent::__construct($name, $data, $dataName); |
44 | 44 | } |
45 | 45 | |
46 | 46 | public function setUp(): void |
47 | 47 | { |
48 | - if (! \class_exists(Kernel::class)) { |
|
48 | + if (!\class_exists(Kernel::class)){ |
|
49 | 49 | $this->markTestSkipped('A "spiral/framework" dependency is required to run these tests'); |
50 | 50 | } |
51 | 51 | |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | 'cache' => sys_get_temp_dir() |
57 | 57 | ], null, false); |
58 | 58 | |
59 | - foreach (static::STORE as $name) { |
|
59 | + foreach (static::STORE as $name){ |
|
60 | 60 | $this->storage->store($name); |
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | 64 | public function tearDown(): void |
65 | 65 | { |
66 | - foreach (static::STORE as $name) { |
|
66 | + foreach (static::STORE as $name){ |
|
67 | 67 | $this->storage->restore($name); |
68 | 68 | } |
69 | 69 | } |
@@ -45,7 +45,8 @@ discard block |
||
45 | 45 | |
46 | 46 | public function setUp(): void |
47 | 47 | { |
48 | - if (! \class_exists(Kernel::class)) { |
|
48 | + if (! \class_exists(Kernel::class)) |
|
49 | + { |
|
49 | 50 | $this->markTestSkipped('A "spiral/framework" dependency is required to run these tests'); |
50 | 51 | } |
51 | 52 | |
@@ -56,14 +57,16 @@ discard block |
||
56 | 57 | 'cache' => sys_get_temp_dir() |
57 | 58 | ], null, false); |
58 | 59 | |
59 | - foreach (static::STORE as $name) { |
|
60 | + foreach (static::STORE as $name) |
|
61 | + { |
|
60 | 62 | $this->storage->store($name); |
61 | 63 | } |
62 | 64 | } |
63 | 65 | |
64 | 66 | public function tearDown(): void |
65 | 67 | { |
66 | - foreach (static::STORE as $name) { |
|
68 | + foreach (static::STORE as $name) |
|
69 | + { |
|
67 | 70 | $this->storage->restore($name); |
68 | 71 | } |
69 | 72 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function jsonSerialize(): array |
47 | 47 | { |
48 | - if ($this->grid === null) { |
|
48 | + if ($this->grid === null){ |
|
49 | 49 | return [ |
50 | 50 | 'status' => 500, |
51 | 51 | 'error' => 'missing-grid-source', |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | $this->option('property', 'data') => $this->data, |
58 | 58 | ]; |
59 | 59 | |
60 | - if ($this->grid->getOption(GridInterface::PAGINATOR) !== null) { |
|
60 | + if ($this->grid->getOption(GridInterface::PAGINATOR) !== null){ |
|
61 | 61 | $response['pagination'] = $this->grid->getOption(GridInterface::PAGINATOR); |
62 | 62 | } |
63 | 63 | |
64 | - if (isset($response['pagination']) && $this->grid->getOption(GridInterface::COUNT) !== null) { |
|
64 | + if (isset($response['pagination']) && $this->grid->getOption(GridInterface::COUNT) !== null){ |
|
65 | 65 | $response['pagination']['count'] = $this->grid->getOption(GridInterface::COUNT); |
66 | 66 | } |
67 | 67 |
@@ -45,7 +45,8 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function jsonSerialize(): array |
47 | 47 | { |
48 | - if ($this->grid === null) { |
|
48 | + if ($this->grid === null) |
|
49 | + { |
|
49 | 50 | return [ |
50 | 51 | 'status' => 500, |
51 | 52 | 'error' => 'missing-grid-source', |
@@ -57,11 +58,13 @@ discard block |
||
57 | 58 | $this->option('property', 'data') => $this->data, |
58 | 59 | ]; |
59 | 60 | |
60 | - if ($this->grid->getOption(GridInterface::PAGINATOR) !== null) { |
|
61 | + if ($this->grid->getOption(GridInterface::PAGINATOR) !== null) |
|
62 | + { |
|
61 | 63 | $response['pagination'] = $this->grid->getOption(GridInterface::PAGINATOR); |
62 | 64 | } |
63 | 65 | |
64 | - if (isset($response['pagination']) && $this->grid->getOption(GridInterface::COUNT) !== null) { |
|
66 | + if (isset($response['pagination']) && $this->grid->getOption(GridInterface::COUNT) !== null) |
|
67 | + { |
|
65 | 68 | $response['pagination']['count'] = $this->grid->getOption(GridInterface::COUNT); |
66 | 69 | } |
67 | 70 |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | GridResponseInterface $response, |
48 | 48 | ContainerInterface $container, |
49 | 49 | GridFactory $gridFactory |
50 | - ) { |
|
50 | + ){ |
|
51 | 51 | $this->response = $response; |
52 | 52 | $this->container = $container; |
53 | 53 | $this->gridFactory = $gridFactory; |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | { |
66 | 66 | $result = $core->callAction($controller, $action, $parameters); |
67 | 67 | |
68 | - if (is_iterable($result)) { |
|
68 | + if (is_iterable($result)){ |
|
69 | 69 | $schema = $this->getSchema($controller, $action); |
70 | - if ($schema !== null) { |
|
70 | + if ($schema !== null){ |
|
71 | 71 | $grid = $this->gridFactory |
72 | 72 | ->withDefaults($schema['defaults']) |
73 | 73 | ->create($result, $schema['grid']); |
74 | 74 | |
75 | - if ($schema['view'] !== null) { |
|
75 | + if ($schema['view'] !== null){ |
|
76 | 76 | $grid = $grid->withView($schema['view']); |
77 | 77 | } |
78 | 78 | |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | private function getSchema(string $controller, string $action): ?array |
93 | 93 | { |
94 | 94 | $key = sprintf('%s:%s', $controller, $action); |
95 | - if (array_key_exists($key, $this->cache)) { |
|
95 | + if (array_key_exists($key, $this->cache)){ |
|
96 | 96 | return $this->cache[$key]; |
97 | 97 | } |
98 | 98 | |
99 | 99 | $this->cache[$key] = null; |
100 | - try { |
|
100 | + try{ |
|
101 | 101 | $method = new \ReflectionMethod($controller, $action); |
102 | - } catch (\ReflectionException $e) { |
|
102 | + }catch (\ReflectionException $e){ |
|
103 | 103 | return null; |
104 | 104 | } |
105 | 105 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | /** @var DataGrid $dataGrid */ |
109 | 109 | $dataGrid = $reader->getMethodAnnotation($method, DataGrid::class); |
110 | - if ($dataGrid === null) { |
|
110 | + if ($dataGrid === null){ |
|
111 | 111 | return null; |
112 | 112 | } |
113 | 113 | |
@@ -127,19 +127,19 @@ discard block |
||
127 | 127 | 'defaults' => $dataGrid->defaults, |
128 | 128 | ]; |
129 | 129 | |
130 | - if (is_string($schema['view'])) { |
|
130 | + if (is_string($schema['view'])){ |
|
131 | 131 | $schema['view'] = $this->container->get($schema['view']); |
132 | 132 | } |
133 | 133 | |
134 | - if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')) { |
|
134 | + if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')){ |
|
135 | 135 | $schema['defaults'] = $schema['grid']->getDefaults(); |
136 | 136 | } |
137 | 137 | |
138 | - if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')) { |
|
138 | + if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')){ |
|
139 | 139 | $schema['options'] = $schema['grid']->getOptions(); |
140 | 140 | } |
141 | 141 | |
142 | - if ($schema['view'] === null && is_callable($schema['grid'])) { |
|
142 | + if ($schema['view'] === null && is_callable($schema['grid'])){ |
|
143 | 143 | $schema['view'] = $schema['grid']; |
144 | 144 | } |
145 | 145 |
@@ -65,14 +65,17 @@ discard block |
||
65 | 65 | { |
66 | 66 | $result = $core->callAction($controller, $action, $parameters); |
67 | 67 | |
68 | - if (is_iterable($result)) { |
|
68 | + if (is_iterable($result)) |
|
69 | + { |
|
69 | 70 | $schema = $this->getSchema($controller, $action); |
70 | - if ($schema !== null) { |
|
71 | + if ($schema !== null) |
|
72 | + { |
|
71 | 73 | $grid = $this->gridFactory |
72 | 74 | ->withDefaults($schema['defaults']) |
73 | 75 | ->create($result, $schema['grid']); |
74 | 76 | |
75 | - if ($schema['view'] !== null) { |
|
77 | + if ($schema['view'] !== null) |
|
78 | + { |
|
76 | 79 | $grid = $grid->withView($schema['view']); |
77 | 80 | } |
78 | 81 | |
@@ -92,14 +95,18 @@ discard block |
||
92 | 95 | private function getSchema(string $controller, string $action): ?array |
93 | 96 | { |
94 | 97 | $key = sprintf('%s:%s', $controller, $action); |
95 | - if (array_key_exists($key, $this->cache)) { |
|
98 | + if (array_key_exists($key, $this->cache)) |
|
99 | + { |
|
96 | 100 | return $this->cache[$key]; |
97 | 101 | } |
98 | 102 | |
99 | 103 | $this->cache[$key] = null; |
100 | - try { |
|
104 | + try |
|
105 | + { |
|
101 | 106 | $method = new \ReflectionMethod($controller, $action); |
102 | - } catch (\ReflectionException $e) { |
|
107 | + } |
|
108 | + catch (\ReflectionException $e) |
|
109 | + { |
|
103 | 110 | return null; |
104 | 111 | } |
105 | 112 | |
@@ -107,7 +114,8 @@ discard block |
||
107 | 114 | |
108 | 115 | /** @var DataGrid $dataGrid */ |
109 | 116 | $dataGrid = $reader->getMethodAnnotation($method, DataGrid::class); |
110 | - if ($dataGrid === null) { |
|
117 | + if ($dataGrid === null) |
|
118 | + { |
|
111 | 119 | return null; |
112 | 120 | } |
113 | 121 | |
@@ -127,19 +135,23 @@ discard block |
||
127 | 135 | 'defaults' => $dataGrid->defaults, |
128 | 136 | ]; |
129 | 137 | |
130 | - if (is_string($schema['view'])) { |
|
138 | + if (is_string($schema['view'])) |
|
139 | + { |
|
131 | 140 | $schema['view'] = $this->container->get($schema['view']); |
132 | 141 | } |
133 | 142 | |
134 | - if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')) { |
|
143 | + if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')) |
|
144 | + { |
|
135 | 145 | $schema['defaults'] = $schema['grid']->getDefaults(); |
136 | 146 | } |
137 | 147 | |
138 | - if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')) { |
|
148 | + if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')) |
|
149 | + { |
|
139 | 150 | $schema['options'] = $schema['grid']->getOptions(); |
140 | 151 | } |
141 | 152 | |
142 | - if ($schema['view'] === null && is_callable($schema['grid'])) { |
|
153 | + if ($schema['view'] === null && is_callable($schema['grid'])) |
|
154 | + { |
|
143 | 155 | $schema['view'] = $schema['grid']; |
144 | 156 | } |
145 | 157 |
@@ -52,23 +52,23 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function write($source, SpecificationInterface $specification, Compiler $compiler) |
54 | 54 | { |
55 | - if (!$this->targetAcceptable($source)) { |
|
55 | + if (!$this->targetAcceptable($source)){ |
|
56 | 56 | return null; |
57 | 57 | } |
58 | 58 | |
59 | - if ($specification instanceof Specification\FilterInterface) { |
|
59 | + if ($specification instanceof Specification\FilterInterface){ |
|
60 | 60 | return $this->writeFilter($source, $specification, $compiler); |
61 | 61 | } |
62 | 62 | |
63 | - if ($specification instanceof Specification\SorterInterface) { |
|
63 | + if ($specification instanceof Specification\SorterInterface){ |
|
64 | 64 | return $this->writeSorter($source, $specification, $compiler); |
65 | 65 | } |
66 | 66 | |
67 | - if ($specification instanceof Specification\Pagination\Limit) { |
|
67 | + if ($specification instanceof Specification\Pagination\Limit){ |
|
68 | 68 | return $source->limit($specification->getValue()); |
69 | 69 | } |
70 | 70 | |
71 | - if ($specification instanceof Specification\Pagination\Offset) { |
|
71 | + if ($specification instanceof Specification\Pagination\Offset){ |
|
72 | 72 | return $source->offset($specification->getValue()); |
73 | 73 | } |
74 | 74 | |
@@ -83,15 +83,15 @@ discard block |
||
83 | 83 | */ |
84 | 84 | protected function writeFilter($source, Specification\FilterInterface $filter, Compiler $compiler) |
85 | 85 | { |
86 | - if ($filter instanceof Specification\Filter\All || $filter instanceof Specification\Filter\Map) { |
|
86 | + if ($filter instanceof Specification\Filter\All || $filter instanceof Specification\Filter\Map){ |
|
87 | 87 | return $source->where(static function () use ($compiler, $filter, $source): void { |
88 | 88 | $compiler->compile($source, ...$filter->getFilters()); |
89 | 89 | }); |
90 | 90 | } |
91 | 91 | |
92 | - if ($filter instanceof Specification\Filter\Any) { |
|
92 | + if ($filter instanceof Specification\Filter\Any){ |
|
93 | 93 | return $source->where(static function () use ($compiler, $filter, $source): void { |
94 | - foreach ($filter->getFilters() as $subFilter) { |
|
94 | + foreach ($filter->getFilters() as $subFilter){ |
|
95 | 95 | $source->orWhere(static function () use ($compiler, $subFilter, $source): void { |
96 | 96 | $compiler->compile($source, $subFilter); |
97 | 97 | }); |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | }); |
100 | 100 | } |
101 | 101 | |
102 | - if ($filter instanceof Specification\Filter\InjectionFilter) { |
|
102 | + if ($filter instanceof Specification\Filter\InjectionFilter){ |
|
103 | 103 | $expression = $filter->getFilter(); |
104 | - if ($expression instanceof Specification\Filter\Expression) { |
|
104 | + if ($expression instanceof Specification\Filter\Expression){ |
|
105 | 105 | return $source->where( |
106 | 106 | $filter->getInjection(), |
107 | 107 | $this->getExpressionOperator($expression), |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | - if ($filter instanceof Specification\Filter\Expression) { |
|
113 | + if ($filter instanceof Specification\Filter\Expression){ |
|
114 | 114 | return $source->where( |
115 | 115 | $filter->getExpression(), |
116 | 116 | $this->getExpressionOperator($filter), |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function getExpressionOperator(Specification\Filter\Expression $filter): string |
129 | 129 | { |
130 | - if ($filter instanceof Specification\Filter\Like) { |
|
130 | + if ($filter instanceof Specification\Filter\Like){ |
|
131 | 131 | return 'LIKE'; |
132 | 132 | } |
133 | 133 | |
134 | - if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) { |
|
134 | + if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray){ |
|
135 | 135 | return self::ARRAY_OPERATORS[get_class($filter)]; |
136 | 136 | } |
137 | 137 | |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | */ |
145 | 145 | protected function getExpressionArgs(Specification\Filter\Expression $filter): array |
146 | 146 | { |
147 | - if ($filter instanceof Specification\Filter\Like) { |
|
147 | + if ($filter instanceof Specification\Filter\Like){ |
|
148 | 148 | return [sprintf($filter->getPattern(), $this->fetchValue($filter->getValue()))]; |
149 | 149 | } |
150 | 150 | |
151 | - if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) { |
|
151 | + if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray){ |
|
152 | 152 | return [new Parameter($this->fetchValue($filter->getValue()))]; |
153 | 153 | } |
154 | 154 | |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | */ |
164 | 164 | protected function writeSorter($source, Specification\SorterInterface $sorter, Compiler $compiler) |
165 | 165 | { |
166 | - if ($sorter instanceof Specification\Sorter\SorterSet) { |
|
167 | - foreach ($sorter->getSorters() as $subSorter) { |
|
166 | + if ($sorter instanceof Specification\Sorter\SorterSet){ |
|
167 | + foreach ($sorter->getSorters() as $subSorter){ |
|
168 | 168 | $source = $compiler->compile($source, $subSorter); |
169 | 169 | } |
170 | 170 | |
@@ -174,9 +174,9 @@ discard block |
||
174 | 174 | if ( |
175 | 175 | $sorter instanceof Specification\Sorter\AscSorter |
176 | 176 | || $sorter instanceof Specification\Sorter\DescSorter |
177 | - ) { |
|
177 | + ){ |
|
178 | 178 | $direction = static::SORTER_DIRECTIONS[get_class($sorter)]; |
179 | - foreach ($sorter->getExpressions() as $expression) { |
|
179 | + foreach ($sorter->getExpressions() as $expression){ |
|
180 | 180 | $source = $source->orderBy($expression, $direction); |
181 | 181 | } |
182 | 182 | |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | protected function fetchValue($value) |
196 | 196 | { |
197 | - if ($value instanceof Specification\ValueInterface) { |
|
197 | + if ($value instanceof Specification\ValueInterface){ |
|
198 | 198 | throw new CompilerException('Value expects user input, none given'); |
199 | 199 | } |
200 | 200 | |
@@ -207,11 +207,11 @@ discard block |
||
207 | 207 | */ |
208 | 208 | protected function targetAcceptable($target): bool |
209 | 209 | { |
210 | - if (class_exists(SelectQuery::class) && $target instanceof SelectQuery) { |
|
210 | + if (class_exists(SelectQuery::class) && $target instanceof SelectQuery){ |
|
211 | 211 | return true; |
212 | 212 | } |
213 | 213 | |
214 | - if (class_exists(Select::class) && $target instanceof Select) { |
|
214 | + if (class_exists(Select::class) && $target instanceof Select){ |
|
215 | 215 | return true; |
216 | 216 | } |
217 | 217 |
@@ -52,23 +52,28 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function write($source, SpecificationInterface $specification, Compiler $compiler) |
54 | 54 | { |
55 | - if (!$this->targetAcceptable($source)) { |
|
55 | + if (!$this->targetAcceptable($source)) |
|
56 | + { |
|
56 | 57 | return null; |
57 | 58 | } |
58 | 59 | |
59 | - if ($specification instanceof Specification\FilterInterface) { |
|
60 | + if ($specification instanceof Specification\FilterInterface) |
|
61 | + { |
|
60 | 62 | return $this->writeFilter($source, $specification, $compiler); |
61 | 63 | } |
62 | 64 | |
63 | - if ($specification instanceof Specification\SorterInterface) { |
|
65 | + if ($specification instanceof Specification\SorterInterface) |
|
66 | + { |
|
64 | 67 | return $this->writeSorter($source, $specification, $compiler); |
65 | 68 | } |
66 | 69 | |
67 | - if ($specification instanceof Specification\Pagination\Limit) { |
|
70 | + if ($specification instanceof Specification\Pagination\Limit) |
|
71 | + { |
|
68 | 72 | return $source->limit($specification->getValue()); |
69 | 73 | } |
70 | 74 | |
71 | - if ($specification instanceof Specification\Pagination\Offset) { |
|
75 | + if ($specification instanceof Specification\Pagination\Offset) |
|
76 | + { |
|
72 | 77 | return $source->offset($specification->getValue()); |
73 | 78 | } |
74 | 79 | |
@@ -83,15 +88,18 @@ discard block |
||
83 | 88 | */ |
84 | 89 | protected function writeFilter($source, Specification\FilterInterface $filter, Compiler $compiler) |
85 | 90 | { |
86 | - if ($filter instanceof Specification\Filter\All || $filter instanceof Specification\Filter\Map) { |
|
91 | + if ($filter instanceof Specification\Filter\All || $filter instanceof Specification\Filter\Map) |
|
92 | + { |
|
87 | 93 | return $source->where(static function () use ($compiler, $filter, $source): void { |
88 | 94 | $compiler->compile($source, ...$filter->getFilters()); |
89 | 95 | }); |
90 | 96 | } |
91 | 97 | |
92 | - if ($filter instanceof Specification\Filter\Any) { |
|
98 | + if ($filter instanceof Specification\Filter\Any) |
|
99 | + { |
|
93 | 100 | return $source->where(static function () use ($compiler, $filter, $source): void { |
94 | - foreach ($filter->getFilters() as $subFilter) { |
|
101 | + foreach ($filter->getFilters() as $subFilter) |
|
102 | + { |
|
95 | 103 | $source->orWhere(static function () use ($compiler, $subFilter, $source): void { |
96 | 104 | $compiler->compile($source, $subFilter); |
97 | 105 | }); |
@@ -99,9 +107,11 @@ discard block |
||
99 | 107 | }); |
100 | 108 | } |
101 | 109 | |
102 | - if ($filter instanceof Specification\Filter\InjectionFilter) { |
|
110 | + if ($filter instanceof Specification\Filter\InjectionFilter) |
|
111 | + { |
|
103 | 112 | $expression = $filter->getFilter(); |
104 | - if ($expression instanceof Specification\Filter\Expression) { |
|
113 | + if ($expression instanceof Specification\Filter\Expression) |
|
114 | + { |
|
105 | 115 | return $source->where( |
106 | 116 | $filter->getInjection(), |
107 | 117 | $this->getExpressionOperator($expression), |
@@ -110,7 +120,8 @@ discard block |
||
110 | 120 | } |
111 | 121 | } |
112 | 122 | |
113 | - if ($filter instanceof Specification\Filter\Expression) { |
|
123 | + if ($filter instanceof Specification\Filter\Expression) |
|
124 | + { |
|
114 | 125 | return $source->where( |
115 | 126 | $filter->getExpression(), |
116 | 127 | $this->getExpressionOperator($filter), |
@@ -127,11 +138,13 @@ discard block |
||
127 | 138 | */ |
128 | 139 | protected function getExpressionOperator(Specification\Filter\Expression $filter): string |
129 | 140 | { |
130 | - if ($filter instanceof Specification\Filter\Like) { |
|
141 | + if ($filter instanceof Specification\Filter\Like) |
|
142 | + { |
|
131 | 143 | return 'LIKE'; |
132 | 144 | } |
133 | 145 | |
134 | - if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) { |
|
146 | + if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) |
|
147 | + { |
|
135 | 148 | return self::ARRAY_OPERATORS[get_class($filter)]; |
136 | 149 | } |
137 | 150 | |
@@ -144,11 +157,13 @@ discard block |
||
144 | 157 | */ |
145 | 158 | protected function getExpressionArgs(Specification\Filter\Expression $filter): array |
146 | 159 | { |
147 | - if ($filter instanceof Specification\Filter\Like) { |
|
160 | + if ($filter instanceof Specification\Filter\Like) |
|
161 | + { |
|
148 | 162 | return [sprintf($filter->getPattern(), $this->fetchValue($filter->getValue()))]; |
149 | 163 | } |
150 | 164 | |
151 | - if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) { |
|
165 | + if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) |
|
166 | + { |
|
152 | 167 | return [new Parameter($this->fetchValue($filter->getValue()))]; |
153 | 168 | } |
154 | 169 | |
@@ -163,8 +178,10 @@ discard block |
||
163 | 178 | */ |
164 | 179 | protected function writeSorter($source, Specification\SorterInterface $sorter, Compiler $compiler) |
165 | 180 | { |
166 | - if ($sorter instanceof Specification\Sorter\SorterSet) { |
|
167 | - foreach ($sorter->getSorters() as $subSorter) { |
|
181 | + if ($sorter instanceof Specification\Sorter\SorterSet) |
|
182 | + { |
|
183 | + foreach ($sorter->getSorters() as $subSorter) |
|
184 | + { |
|
168 | 185 | $source = $compiler->compile($source, $subSorter); |
169 | 186 | } |
170 | 187 | |
@@ -176,7 +193,8 @@ discard block |
||
176 | 193 | || $sorter instanceof Specification\Sorter\DescSorter |
177 | 194 | ) { |
178 | 195 | $direction = static::SORTER_DIRECTIONS[get_class($sorter)]; |
179 | - foreach ($sorter->getExpressions() as $expression) { |
|
196 | + foreach ($sorter->getExpressions() as $expression) |
|
197 | + { |
|
180 | 198 | $source = $source->orderBy($expression, $direction); |
181 | 199 | } |
182 | 200 | |
@@ -194,7 +212,8 @@ discard block |
||
194 | 212 | */ |
195 | 213 | protected function fetchValue($value) |
196 | 214 | { |
197 | - if ($value instanceof Specification\ValueInterface) { |
|
215 | + if ($value instanceof Specification\ValueInterface) |
|
216 | + { |
|
198 | 217 | throw new CompilerException('Value expects user input, none given'); |
199 | 218 | } |
200 | 219 | |
@@ -207,11 +226,13 @@ discard block |
||
207 | 226 | */ |
208 | 227 | protected function targetAcceptable($target): bool |
209 | 228 | { |
210 | - if (class_exists(SelectQuery::class) && $target instanceof SelectQuery) { |
|
229 | + if (class_exists(SelectQuery::class) && $target instanceof SelectQuery) |
|
230 | + { |
|
211 | 231 | return true; |
212 | 232 | } |
213 | 233 | |
214 | - if (class_exists(Select::class) && $target instanceof Select) { |
|
234 | + if (class_exists(Select::class) && $target instanceof Select) |
|
235 | + { |
|
215 | 236 | return true; |
216 | 237 | } |
217 | 238 |
@@ -35,20 +35,20 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function write($source, SpecificationInterface $specification, Compiler $compiler) |
37 | 37 | { |
38 | - if ($specification instanceof Filter\Between || $specification instanceof Filter\ValueBetween) { |
|
38 | + if ($specification instanceof Filter\Between || $specification instanceof Filter\ValueBetween){ |
|
39 | 39 | $filters = $specification->getFilters($this->asOriginal); |
40 | - if (count($filters) > 1) { |
|
40 | + if (count($filters) > 1){ |
|
41 | 41 | return $source->where(static function () use ($compiler, $source, $filters): void { |
42 | 42 | $compiler->compile($source, ...$filters); |
43 | 43 | }); |
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | - if ($specification instanceof Filter\InjectionFilter) { |
|
47 | + if ($specification instanceof Filter\InjectionFilter){ |
|
48 | 48 | $expression = $specification->getFilter(); |
49 | - if ($expression instanceof Filter\Between) { |
|
49 | + if ($expression instanceof Filter\Between){ |
|
50 | 50 | $filters = $expression->getFilters($this->asOriginal); |
51 | - if (count($filters) > 1) { |
|
51 | + if (count($filters) > 1){ |
|
52 | 52 | $filters = array_map( |
53 | 53 | static function (SpecificationInterface $filter) use ($specification): Filter\InjectionFilter { |
54 | 54 | return Filter\InjectionFilter::createFrom($specification, $filter); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | - if ($specification instanceof Filter\Between) { |
|
74 | + if ($specification instanceof Filter\Between){ |
|
75 | 75 | return $source->where( |
76 | 76 | $specification->getExpression(), |
77 | 77 | 'BETWEEN', |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | ); |
80 | 80 | } |
81 | 81 | |
82 | - if ($specification instanceof Filter\ValueBetween) { |
|
82 | + if ($specification instanceof Filter\ValueBetween){ |
|
83 | 83 | return $source->where( |
84 | 84 | new Parameter($specification->getValue()), |
85 | 85 | 'BETWEEN', |
@@ -35,20 +35,25 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function write($source, SpecificationInterface $specification, Compiler $compiler) |
37 | 37 | { |
38 | - if ($specification instanceof Filter\Between || $specification instanceof Filter\ValueBetween) { |
|
38 | + if ($specification instanceof Filter\Between || $specification instanceof Filter\ValueBetween) |
|
39 | + { |
|
39 | 40 | $filters = $specification->getFilters($this->asOriginal); |
40 | - if (count($filters) > 1) { |
|
41 | + if (count($filters) > 1) |
|
42 | + { |
|
41 | 43 | return $source->where(static function () use ($compiler, $source, $filters): void { |
42 | 44 | $compiler->compile($source, ...$filters); |
43 | 45 | }); |
44 | 46 | } |
45 | 47 | } |
46 | 48 | |
47 | - if ($specification instanceof Filter\InjectionFilter) { |
|
49 | + if ($specification instanceof Filter\InjectionFilter) |
|
50 | + { |
|
48 | 51 | $expression = $specification->getFilter(); |
49 | - if ($expression instanceof Filter\Between) { |
|
52 | + if ($expression instanceof Filter\Between) |
|
53 | + { |
|
50 | 54 | $filters = $expression->getFilters($this->asOriginal); |
51 | - if (count($filters) > 1) { |
|
55 | + if (count($filters) > 1) |
|
56 | + { |
|
52 | 57 | $filters = array_map( |
53 | 58 | static function (SpecificationInterface $filter) use ($specification): Filter\InjectionFilter { |
54 | 59 | return Filter\InjectionFilter::createFrom($specification, $filter); |
@@ -71,7 +76,8 @@ discard block |
||
71 | 76 | } |
72 | 77 | } |
73 | 78 | |
74 | - if ($specification instanceof Filter\Between) { |
|
79 | + if ($specification instanceof Filter\Between) |
|
80 | + { |
|
75 | 81 | return $source->where( |
76 | 82 | $specification->getExpression(), |
77 | 83 | 'BETWEEN', |
@@ -79,7 +85,8 @@ discard block |
||
79 | 85 | ); |
80 | 86 | } |
81 | 87 | |
82 | - if ($specification instanceof Filter\ValueBetween) { |
|
88 | + if ($specification instanceof Filter\ValueBetween) |
|
89 | + { |
|
83 | 90 | return $source->where( |
84 | 91 | new Parameter($specification->getValue()), |
85 | 92 | 'BETWEEN', |
@@ -66,8 +66,8 @@ |
||
66 | 66 | */ |
67 | 67 | public function compiler(ContainerInterface $container, Compiler $compiler, GridConfig $config): Compiler |
68 | 68 | { |
69 | - if ($container->has(DatabaseInterface::class)) { |
|
70 | - foreach ($config->getWriters() as $writer) { |
|
69 | + if ($container->has(DatabaseInterface::class)){ |
|
70 | + foreach ($config->getWriters() as $writer){ |
|
71 | 71 | $compiler->addWriter($container->get($writer)); |
72 | 72 | } |
73 | 73 | } |
@@ -66,8 +66,10 @@ |
||
66 | 66 | */ |
67 | 67 | public function compiler(ContainerInterface $container, Compiler $compiler, GridConfig $config): Compiler |
68 | 68 | { |
69 | - if ($container->has(DatabaseInterface::class)) { |
|
70 | - foreach ($config->getWriters() as $writer) { |
|
69 | + if ($container->has(DatabaseInterface::class)) |
|
70 | + { |
|
71 | + foreach ($config->getWriters() as $writer) |
|
72 | + { |
|
71 | 73 | $compiler->addWriter($container->get($writer)); |
72 | 74 | } |
73 | 75 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | |
26 | 26 | public function __construct(SpecificationInterface $expression) |
27 | 27 | { |
28 | - if (!$expression instanceof Expression && !$expression instanceof Between) { |
|
28 | + if (!$expression instanceof Expression && !$expression instanceof Between){ |
|
29 | 29 | throw new LogicException('Only expression filters allowed'); |
30 | 30 | } |
31 | 31 |
@@ -25,7 +25,8 @@ |
||
25 | 25 | |
26 | 26 | public function __construct(SpecificationInterface $expression) |
27 | 27 | { |
28 | - if (!$expression instanceof Expression && !$expression instanceof Between) { |
|
28 | + if (!$expression instanceof Expression && !$expression instanceof Between) |
|
29 | + { |
|
29 | 30 | throw new LogicException('Only expression filters allowed'); |
30 | 31 | } |
31 | 32 |