@@ -69,16 +69,16 @@ discard block |
||
69 | 69 | protected function buildMap(ReflectionEntity $filter): array |
70 | 70 | { |
71 | 71 | $schema = $filter->getProperty('schema', true); |
72 | - if (empty($schema)) { |
|
72 | + if (empty($schema)){ |
|
73 | 73 | throw new SchemaException("Filter `{$filter->getName()}` does not define any schema"); |
74 | 74 | } |
75 | 75 | |
76 | 76 | $result = []; |
77 | - foreach ($schema as $field => $definition) { |
|
77 | + foreach ($schema as $field => $definition){ |
|
78 | 78 | // short definition |
79 | - if (is_string($definition)) { |
|
79 | + if (is_string($definition)){ |
|
80 | 80 | // simple scalar field definition |
81 | - if (!class_exists($definition)) { |
|
81 | + if (!class_exists($definition)){ |
|
82 | 82 | [$source, $origin] = $this->parseDefinition($filter, $field, $definition); |
83 | 83 | $result[$field] = [ |
84 | 84 | FilterProvider::SOURCE => $source, |
@@ -98,20 +98,20 @@ discard block |
||
98 | 98 | continue; |
99 | 99 | } |
100 | 100 | |
101 | - if (!is_array($definition) || count($definition) === 0) { |
|
101 | + if (!is_array($definition) || count($definition) === 0){ |
|
102 | 102 | throw new SchemaException( |
103 | 103 | "Invalid schema definition at `{$filter->getName()}`->`{$field}`" |
104 | 104 | ); |
105 | 105 | } |
106 | 106 | |
107 | 107 | // complex definition |
108 | - if (!empty($definition[self::ORIGIN])) { |
|
108 | + if (!empty($definition[self::ORIGIN])){ |
|
109 | 109 | $origin = $definition[self::ORIGIN]; |
110 | 110 | |
111 | 111 | // [class, 'data:something.*'] vs [class, 'data:something'] |
112 | 112 | $iterate = strpos($origin, '.*') !== false || !empty($definition[self::ITERATE]); |
113 | 113 | $origin = rtrim($origin, '.*'); |
114 | - } else { |
|
114 | + }else{ |
|
115 | 115 | $origin = $field; |
116 | 116 | $iterate = true; |
117 | 117 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | FilterProvider::ARRAY => $iterate, |
125 | 125 | ]; |
126 | 126 | |
127 | - if ($iterate) { |
|
127 | + if ($iterate){ |
|
128 | 128 | [$source, $origin] = $this->parseDefinition( |
129 | 129 | $filter, |
130 | 130 | $field, |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | */ |
156 | 156 | private function parseDefinition(ReflectionEntity $filter, string $field, string $definition): array |
157 | 157 | { |
158 | - if (strpos($definition, ':') === false) { |
|
158 | + if (strpos($definition, ':') === false){ |
|
159 | 159 | return ['data', $definition ?? $field]; |
160 | 160 | } |
161 | 161 |
@@ -69,16 +69,20 @@ discard block |
||
69 | 69 | protected function buildMap(ReflectionEntity $filter): array |
70 | 70 | { |
71 | 71 | $schema = $filter->getProperty('schema', true); |
72 | - if (empty($schema)) { |
|
72 | + if (empty($schema)) |
|
73 | + { |
|
73 | 74 | throw new SchemaException("Filter `{$filter->getName()}` does not define any schema"); |
74 | 75 | } |
75 | 76 | |
76 | 77 | $result = []; |
77 | - foreach ($schema as $field => $definition) { |
|
78 | + foreach ($schema as $field => $definition) |
|
79 | + { |
|
78 | 80 | // short definition |
79 | - if (is_string($definition)) { |
|
81 | + if (is_string($definition)) |
|
82 | + { |
|
80 | 83 | // simple scalar field definition |
81 | - if (!class_exists($definition)) { |
|
84 | + if (!class_exists($definition)) |
|
85 | + { |
|
82 | 86 | [$source, $origin] = $this->parseDefinition($filter, $field, $definition); |
83 | 87 | $result[$field] = [ |
84 | 88 | FilterProvider::SOURCE => $source, |
@@ -98,20 +102,24 @@ discard block |
||
98 | 102 | continue; |
99 | 103 | } |
100 | 104 | |
101 | - if (!is_array($definition) || count($definition) === 0) { |
|
105 | + if (!is_array($definition) || count($definition) === 0) |
|
106 | + { |
|
102 | 107 | throw new SchemaException( |
103 | 108 | "Invalid schema definition at `{$filter->getName()}`->`{$field}`" |
104 | 109 | ); |
105 | 110 | } |
106 | 111 | |
107 | 112 | // complex definition |
108 | - if (!empty($definition[self::ORIGIN])) { |
|
113 | + if (!empty($definition[self::ORIGIN])) |
|
114 | + { |
|
109 | 115 | $origin = $definition[self::ORIGIN]; |
110 | 116 | |
111 | 117 | // [class, 'data:something.*'] vs [class, 'data:something'] |
112 | 118 | $iterate = strpos($origin, '.*') !== false || !empty($definition[self::ITERATE]); |
113 | 119 | $origin = rtrim($origin, '.*'); |
114 | - } else { |
|
120 | + } |
|
121 | + else |
|
122 | + { |
|
115 | 123 | $origin = $field; |
116 | 124 | $iterate = true; |
117 | 125 | } |
@@ -124,7 +132,8 @@ discard block |
||
124 | 132 | FilterProvider::ARRAY => $iterate, |
125 | 133 | ]; |
126 | 134 | |
127 | - if ($iterate) { |
|
135 | + if ($iterate) |
|
136 | + { |
|
128 | 137 | [$source, $origin] = $this->parseDefinition( |
129 | 138 | $filter, |
130 | 139 | $field, |
@@ -155,7 +164,8 @@ discard block |
||
155 | 164 | */ |
156 | 165 | private function parseDefinition(ReflectionEntity $filter, string $field, string $definition): array |
157 | 166 | { |
158 | - if (strpos($definition, ':') === false) { |
|
167 | + if (strpos($definition, ':') === false) |
|
168 | + { |
|
159 | 169 | return ['data', $definition ?? $field]; |
160 | 170 | } |
161 | 171 |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | FilterProvider::SOURCE => null, |
93 | 93 | FilterProvider::ORIGIN => $field, |
94 | 94 | FilterProvider::FILTER => $definition, |
95 | - FilterProvider::ARRAY => false, |
|
95 | + FilterProvider::array => false, |
|
96 | 96 | ]; |
97 | 97 | |
98 | 98 | continue; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | FilterProvider::FILTER => $definition[self::NESTED], |
122 | 122 | FilterProvider::SOURCE => null, |
123 | 123 | FilterProvider::ORIGIN => $origin, |
124 | - FilterProvider::ARRAY => $iterate, |
|
124 | + FilterProvider::array => $iterate, |
|
125 | 125 | ]; |
126 | 126 | |
127 | 127 | if ($iterate) { |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | string $extends = '', |
62 | 62 | array $interfaces = [], |
63 | 63 | string $comment = '' |
64 | - ) { |
|
64 | + ){ |
|
65 | 65 | $this->setName($name); |
66 | 66 | |
67 | - if (!empty($extends)) { |
|
67 | + if (!empty($extends)){ |
|
68 | 68 | $this->setExtends($extends); |
69 | 69 | } |
70 | 70 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | public function setInterfaces(array $interfaces): ClassDeclaration |
158 | 158 | { |
159 | 159 | $this->interfaces = []; |
160 | - foreach ($interfaces as $interface) { |
|
160 | + foreach ($interfaces as $interface){ |
|
161 | 161 | $this->addInterface($interface); |
162 | 162 | } |
163 | 163 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | public function setTraits(array $traits): ClassDeclaration |
204 | 204 | { |
205 | 205 | $this->traits = []; |
206 | - foreach ($traits as $trait) { |
|
206 | + foreach ($traits as $trait){ |
|
207 | 207 | $this->addTrait($trait); |
208 | 208 | } |
209 | 209 | |
@@ -293,30 +293,30 @@ discard block |
||
293 | 293 | { |
294 | 294 | $result = ''; |
295 | 295 | |
296 | - if (!$this->docComment->isEmpty()) { |
|
297 | - $result .= $this->docComment->render($indentLevel) . "\n"; |
|
296 | + if (!$this->docComment->isEmpty()){ |
|
297 | + $result .= $this->docComment->render($indentLevel)."\n"; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | //Class header |
301 | 301 | $header = "class {$this->getName()}"; |
302 | 302 | |
303 | 303 | //Rendering extends |
304 | - if (!empty($this->extends)) { |
|
304 | + if (!empty($this->extends)){ |
|
305 | 305 | $header .= " extends {$this->extends}"; |
306 | 306 | } |
307 | 307 | |
308 | - if (!empty($this->interfaces)) { |
|
308 | + if (!empty($this->interfaces)){ |
|
309 | 309 | $interfaces = implode(', ', array_keys($this->interfaces)); |
310 | 310 | $header .= " implements {$interfaces}"; |
311 | 311 | } |
312 | 312 | |
313 | - $result .= $this->addIndent($header, $indentLevel) . "\n"; |
|
314 | - $result .= $this->addIndent('{', $indentLevel) . "\n"; |
|
313 | + $result .= $this->addIndent($header, $indentLevel)."\n"; |
|
314 | + $result .= $this->addIndent('{', $indentLevel)."\n"; |
|
315 | 315 | |
316 | 316 | //Rendering class body |
317 | 317 | $result .= $this->renderBody($indentLevel); |
318 | 318 | |
319 | - $result = rtrim($result, "\n") . "\n"; |
|
319 | + $result = rtrim($result, "\n")."\n"; |
|
320 | 320 | $result .= $this->addIndent('}', $indentLevel); |
321 | 321 | |
322 | 322 | return $result; |
@@ -329,20 +329,20 @@ discard block |
||
329 | 329 | protected function renderBody(int $indentLevel): string |
330 | 330 | { |
331 | 331 | $result = ''; |
332 | - if (!empty($this->traits)) { |
|
333 | - $result .= $this->renderTraits($indentLevel + 1) . "\n\n"; |
|
332 | + if (!empty($this->traits)){ |
|
333 | + $result .= $this->renderTraits($indentLevel + 1)."\n\n"; |
|
334 | 334 | } |
335 | 335 | |
336 | - if (!$this->constants->isEmpty()) { |
|
337 | - $result .= $this->constants->render($indentLevel + 1) . "\n\n"; |
|
336 | + if (!$this->constants->isEmpty()){ |
|
337 | + $result .= $this->constants->render($indentLevel + 1)."\n\n"; |
|
338 | 338 | } |
339 | 339 | |
340 | - if (!$this->properties->isEmpty()) { |
|
341 | - $result .= $this->properties->render($indentLevel + 1) . "\n\n"; |
|
340 | + if (!$this->properties->isEmpty()){ |
|
341 | + $result .= $this->properties->render($indentLevel + 1)."\n\n"; |
|
342 | 342 | } |
343 | 343 | |
344 | - if (!$this->methods->isEmpty()) { |
|
345 | - $result .= $this->methods->render($indentLevel + 1) . "\n\n"; |
|
344 | + if (!$this->methods->isEmpty()){ |
|
345 | + $result .= $this->methods->render($indentLevel + 1)."\n\n"; |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | return $result; |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | private function renderTraits(int $indentLevel = 0): string |
356 | 356 | { |
357 | 357 | $lines = []; |
358 | - foreach ($this->traits as $class => $options) { |
|
358 | + foreach ($this->traits as $class => $options){ |
|
359 | 359 | $lines[] = $this->addIndent("use {$class};", $indentLevel); |
360 | 360 | } |
361 | 361 |
@@ -64,7 +64,8 @@ discard block |
||
64 | 64 | ) { |
65 | 65 | $this->setName($name); |
66 | 66 | |
67 | - if (!empty($extends)) { |
|
67 | + if (!empty($extends)) |
|
68 | + { |
|
68 | 69 | $this->setExtends($extends); |
69 | 70 | } |
70 | 71 | |
@@ -157,7 +158,8 @@ discard block |
||
157 | 158 | public function setInterfaces(array $interfaces): ClassDeclaration |
158 | 159 | { |
159 | 160 | $this->interfaces = []; |
160 | - foreach ($interfaces as $interface) { |
|
161 | + foreach ($interfaces as $interface) |
|
162 | + { |
|
161 | 163 | $this->addInterface($interface); |
162 | 164 | } |
163 | 165 | |
@@ -203,7 +205,8 @@ discard block |
||
203 | 205 | public function setTraits(array $traits): ClassDeclaration |
204 | 206 | { |
205 | 207 | $this->traits = []; |
206 | - foreach ($traits as $trait) { |
|
208 | + foreach ($traits as $trait) |
|
209 | + { |
|
207 | 210 | $this->addTrait($trait); |
208 | 211 | } |
209 | 212 | |
@@ -293,7 +296,8 @@ discard block |
||
293 | 296 | { |
294 | 297 | $result = ''; |
295 | 298 | |
296 | - if (!$this->docComment->isEmpty()) { |
|
299 | + if (!$this->docComment->isEmpty()) |
|
300 | + { |
|
297 | 301 | $result .= $this->docComment->render($indentLevel) . "\n"; |
298 | 302 | } |
299 | 303 | |
@@ -301,11 +305,13 @@ discard block |
||
301 | 305 | $header = "class {$this->getName()}"; |
302 | 306 | |
303 | 307 | //Rendering extends |
304 | - if (!empty($this->extends)) { |
|
308 | + if (!empty($this->extends)) |
|
309 | + { |
|
305 | 310 | $header .= " extends {$this->extends}"; |
306 | 311 | } |
307 | 312 | |
308 | - if (!empty($this->interfaces)) { |
|
313 | + if (!empty($this->interfaces)) |
|
314 | + { |
|
309 | 315 | $interfaces = implode(', ', array_keys($this->interfaces)); |
310 | 316 | $header .= " implements {$interfaces}"; |
311 | 317 | } |
@@ -329,19 +335,23 @@ discard block |
||
329 | 335 | protected function renderBody(int $indentLevel): string |
330 | 336 | { |
331 | 337 | $result = ''; |
332 | - if (!empty($this->traits)) { |
|
338 | + if (!empty($this->traits)) |
|
339 | + { |
|
333 | 340 | $result .= $this->renderTraits($indentLevel + 1) . "\n\n"; |
334 | 341 | } |
335 | 342 | |
336 | - if (!$this->constants->isEmpty()) { |
|
343 | + if (!$this->constants->isEmpty()) |
|
344 | + { |
|
337 | 345 | $result .= $this->constants->render($indentLevel + 1) . "\n\n"; |
338 | 346 | } |
339 | 347 | |
340 | - if (!$this->properties->isEmpty()) { |
|
348 | + if (!$this->properties->isEmpty()) |
|
349 | + { |
|
341 | 350 | $result .= $this->properties->render($indentLevel + 1) . "\n\n"; |
342 | 351 | } |
343 | 352 | |
344 | - if (!$this->methods->isEmpty()) { |
|
353 | + if (!$this->methods->isEmpty()) |
|
354 | + { |
|
345 | 355 | $result .= $this->methods->render($indentLevel + 1) . "\n\n"; |
346 | 356 | } |
347 | 357 | |
@@ -355,7 +365,8 @@ discard block |
||
355 | 365 | private function renderTraits(int $indentLevel = 0): string |
356 | 366 | { |
357 | 367 | $lines = []; |
358 | - foreach ($this->traits as $class => $options) { |
|
368 | + foreach ($this->traits as $class => $options) |
|
369 | + { |
|
359 | 370 | $lines[] = $this->addIndent("use {$class};", $indentLevel); |
360 | 371 | } |
361 | 372 |
@@ -38,7 +38,7 @@ |
||
38 | 38 | AbstractDeclaration::ACCESS_PROTECTED, |
39 | 39 | AbstractDeclaration::ACCESS_PUBLIC, |
40 | 40 | ], true) |
41 | - ) { |
|
41 | + ){ |
|
42 | 42 | throw new ReactorException("Invalid declaration level '{$access}'"); |
43 | 43 | } |
44 | 44 |