@@ -45,7 +45,7 @@ |
||
45 | 45 | public function __construct(string $subject, $to, array $data = []) |
46 | 46 | { |
47 | 47 | $this->setSubject($subject); |
48 | - $this->setTo(...(array) $to); |
|
48 | + $this->setTo(...(array)$to); |
|
49 | 49 | $this->setData($data); |
50 | 50 | } |
51 | 51 |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | */ |
47 | 47 | protected function availableReflections(): \Generator |
48 | 48 | { |
49 | - foreach ($this->finder->getIterator() as $file) { |
|
49 | + foreach ($this->finder->getIterator() as $file){ |
|
50 | 50 | $reflection = new ReflectionFile((string)$file); |
51 | 51 | |
52 | - if ($reflection->hasIncludes()) { |
|
52 | + if ($reflection->hasIncludes()){ |
|
53 | 53 | // We are not analyzing files which has includes, it's not safe to require such reflections |
54 | 54 | $this->getLogger()->warning( |
55 | 55 | sprintf('File `%s` has includes and excluded from analysis', $file), |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | */ |
74 | 74 | protected function classReflection(string $class): \ReflectionClass |
75 | 75 | { |
76 | - $loader = static function ($class) { |
|
77 | - if ($class === LocatorException::class) { |
|
76 | + $loader = static function ($class){ |
|
77 | + if ($class === LocatorException::class){ |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | //To suspend class dependency exception |
85 | 85 | spl_autoload_register($loader); |
86 | 86 | |
87 | - try { |
|
87 | + try{ |
|
88 | 88 | //In some cases reflection can thrown an exception if class invalid or can not be loaded, |
89 | 89 | //we are going to handle such exception and convert it soft exception |
90 | 90 | return new \ReflectionClass($class); |
91 | - } catch (\Throwable $e) { |
|
92 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
91 | + }catch (\Throwable $e){ |
|
92 | + if ($e instanceof LocatorException && $e->getPrevious() != null){ |
|
93 | 93 | $e = $e->getPrevious(); |
94 | 94 | } |
95 | 95 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | ); |
106 | 106 | |
107 | 107 | throw new LocatorException($e->getMessage(), $e->getCode(), $e); |
108 | - } finally { |
|
108 | + }finally{ |
|
109 | 109 | spl_autoload_unregister($loader); |
110 | 110 | } |
111 | 111 | } |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | { |
122 | 122 | $traits = []; |
123 | 123 | |
124 | - while ($class) { |
|
124 | + while ($class){ |
|
125 | 125 | $traits = array_merge(class_uses($class), $traits); |
126 | 126 | $class = get_parent_class($class); |
127 | 127 | } |
128 | 128 | |
129 | 129 | //Traits from traits |
130 | - foreach (array_flip($traits) as $trait) { |
|
130 | + foreach (array_flip($traits) as $trait){ |
|
131 | 131 | $traits = array_merge(class_uses($trait), $traits); |
132 | 132 | } |
133 | 133 |
@@ -46,10 +46,12 @@ discard block |
||
46 | 46 | */ |
47 | 47 | protected function availableReflections(): \Generator |
48 | 48 | { |
49 | - foreach ($this->finder->getIterator() as $file) { |
|
49 | + foreach ($this->finder->getIterator() as $file) |
|
50 | + { |
|
50 | 51 | $reflection = new ReflectionFile((string)$file); |
51 | 52 | |
52 | - if ($reflection->hasIncludes()) { |
|
53 | + if ($reflection->hasIncludes()) |
|
54 | + { |
|
53 | 55 | // We are not analyzing files which has includes, it's not safe to require such reflections |
54 | 56 | $this->getLogger()->warning( |
55 | 57 | sprintf('File `%s` has includes and excluded from analysis', $file), |
@@ -73,8 +75,10 @@ discard block |
||
73 | 75 | */ |
74 | 76 | protected function classReflection(string $class): \ReflectionClass |
75 | 77 | { |
76 | - $loader = static function ($class) { |
|
77 | - if ($class === LocatorException::class) { |
|
78 | + $loader = static function ($class) |
|
79 | + { |
|
80 | + if ($class === LocatorException::class) |
|
81 | + { |
|
78 | 82 | return; |
79 | 83 | } |
80 | 84 | |
@@ -84,12 +88,16 @@ discard block |
||
84 | 88 | //To suspend class dependency exception |
85 | 89 | spl_autoload_register($loader); |
86 | 90 | |
87 | - try { |
|
91 | + try |
|
92 | + { |
|
88 | 93 | //In some cases reflection can thrown an exception if class invalid or can not be loaded, |
89 | 94 | //we are going to handle such exception and convert it soft exception |
90 | 95 | return new \ReflectionClass($class); |
91 | - } catch (\Throwable $e) { |
|
92 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
96 | + } |
|
97 | + catch (\Throwable $e) |
|
98 | + { |
|
99 | + if ($e instanceof LocatorException && $e->getPrevious() != null) |
|
100 | + { |
|
93 | 101 | $e = $e->getPrevious(); |
94 | 102 | } |
95 | 103 | |
@@ -105,7 +113,9 @@ discard block |
||
105 | 113 | ); |
106 | 114 | |
107 | 115 | throw new LocatorException($e->getMessage(), $e->getCode(), $e); |
108 | - } finally { |
|
116 | + } |
|
117 | + finally |
|
118 | + { |
|
109 | 119 | spl_autoload_unregister($loader); |
110 | 120 | } |
111 | 121 | } |
@@ -121,13 +131,15 @@ discard block |
||
121 | 131 | { |
122 | 132 | $traits = []; |
123 | 133 | |
124 | - while ($class) { |
|
134 | + while ($class) |
|
135 | + { |
|
125 | 136 | $traits = array_merge(class_uses($class), $traits); |
126 | 137 | $class = get_parent_class($class); |
127 | 138 | } |
128 | 139 | |
129 | 140 | //Traits from traits |
130 | - foreach (array_flip($traits) as $trait) { |
|
141 | + foreach (array_flip($traits) as $trait) |
|
142 | + { |
|
131 | 143 | $traits = array_merge(class_uses($trait), $traits); |
132 | 144 | } |
133 | 145 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function serialize($value): string |
37 | 37 | { |
38 | - if (is_array($value)) { |
|
38 | + if (is_array($value)){ |
|
39 | 39 | return $this->packArray($value); |
40 | 40 | } |
41 | 41 | |
@@ -50,49 +50,49 @@ discard block |
||
50 | 50 | */ |
51 | 51 | protected function packArray(array $array, int $level = 0): string |
52 | 52 | { |
53 | - if ($array === []) { |
|
53 | + if ($array === []){ |
|
54 | 54 | return '[]'; |
55 | 55 | } |
56 | 56 | //Delimiters between rows and sub-arrays. |
57 | - $subIndent = "\n" . str_repeat(self::INDENT, $level + 2); |
|
58 | - $keyIndent = "\n" . str_repeat(self::INDENT, $level + 1); |
|
57 | + $subIndent = "\n".str_repeat(self::INDENT, $level + 2); |
|
58 | + $keyIndent = "\n".str_repeat(self::INDENT, $level + 1); |
|
59 | 59 | //No keys for associated array |
60 | 60 | $associated = array_diff_key($array, array_keys(array_keys($array))); |
61 | 61 | $result = []; |
62 | 62 | $innerIndent = 0; |
63 | - if (!empty($associated)) { |
|
64 | - foreach ($array as $key => $_) { |
|
63 | + if (!empty($associated)){ |
|
64 | + foreach ($array as $key => $_){ |
|
65 | 65 | //Based on biggest key length |
66 | 66 | $innerIndent = max(strlen(var_export($key, true)), $innerIndent); |
67 | 67 | } |
68 | 68 | } |
69 | - foreach ($array as $key => $value) { |
|
69 | + foreach ($array as $key => $value){ |
|
70 | 70 | $prefix = ''; |
71 | - if (!empty($associated)) { |
|
71 | + if (!empty($associated)){ |
|
72 | 72 | //Key prefix |
73 | 73 | $prefix = str_pad( |
74 | 74 | var_export($key, true), |
75 | 75 | $innerIndent, |
76 | 76 | ' ', |
77 | 77 | STR_PAD_RIGHT |
78 | - ) . ' => '; |
|
78 | + ).' => '; |
|
79 | 79 | } |
80 | - if (!is_array($value)) { |
|
81 | - $result[] = $prefix . $this->packValue($value); |
|
80 | + if (!is_array($value)){ |
|
81 | + $result[] = $prefix.$this->packValue($value); |
|
82 | 82 | continue; |
83 | 83 | } |
84 | - if ($value === []) { |
|
85 | - $result[] = $prefix . '[]'; |
|
84 | + if ($value === []){ |
|
85 | + $result[] = $prefix.'[]'; |
|
86 | 86 | continue; |
87 | 87 | } |
88 | 88 | $subArray = $this->packArray($value, $level + 1); |
89 | - $result[] = $prefix . "[{$subIndent}" . $subArray . "{$keyIndent}]"; |
|
89 | + $result[] = $prefix."[{$subIndent}".$subArray."{$keyIndent}]"; |
|
90 | 90 | } |
91 | - if ($level !== 0) { |
|
91 | + if ($level !== 0){ |
|
92 | 92 | return $result ? implode(",{$keyIndent}", $result) : ''; |
93 | 93 | } |
94 | 94 | |
95 | - return "[{$keyIndent}" . implode(",{$keyIndent}", $result) . "\n]"; |
|
95 | + return "[{$keyIndent}".implode(",{$keyIndent}", $result)."\n]"; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -105,31 +105,31 @@ discard block |
||
105 | 105 | */ |
106 | 106 | protected function packValue($value): string |
107 | 107 | { |
108 | - if ($value instanceof DeclarationInterface) { |
|
108 | + if ($value instanceof DeclarationInterface){ |
|
109 | 109 | //No indentation here |
110 | 110 | return $value->render(); |
111 | 111 | } |
112 | 112 | |
113 | - if ($value === null) { |
|
113 | + if ($value === null){ |
|
114 | 114 | return 'null'; |
115 | 115 | } |
116 | 116 | |
117 | - if (is_bool($value)) { |
|
117 | + if (is_bool($value)){ |
|
118 | 118 | return ($value ? 'true' : 'false'); |
119 | 119 | } |
120 | 120 | |
121 | - if (is_object($value) && method_exists($value, '__set_state')) { |
|
122 | - return '\\' . var_export($value, true); |
|
121 | + if (is_object($value) && method_exists($value, '__set_state')){ |
|
122 | + return '\\'.var_export($value, true); |
|
123 | 123 | } |
124 | 124 | |
125 | - if (!is_string($value) && !is_numeric($value)) { |
|
125 | + if (!is_string($value) && !is_numeric($value)){ |
|
126 | 126 | throw new SerializeException('Unable to pack non scalar value'); |
127 | 127 | } |
128 | 128 | |
129 | - if (is_string($value) && class_exists($value)) { |
|
129 | + if (is_string($value) && class_exists($value)){ |
|
130 | 130 | $reflection = new ReflectionClass($value); |
131 | - if ($value === $reflection->getName()) { |
|
132 | - return '\\' . $reflection->getName() . '::class'; |
|
131 | + if ($value === $reflection->getName()){ |
|
132 | + return '\\'.$reflection->getName().'::class'; |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 |
@@ -35,7 +35,8 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function serialize($value): string |
37 | 37 | { |
38 | - if (is_array($value)) { |
|
38 | + if (is_array($value)) |
|
39 | + { |
|
39 | 40 | return $this->packArray($value); |
40 | 41 | } |
41 | 42 | |
@@ -50,7 +51,8 @@ discard block |
||
50 | 51 | */ |
51 | 52 | protected function packArray(array $array, int $level = 0): string |
52 | 53 | { |
53 | - if ($array === []) { |
|
54 | + if ($array === []) |
|
55 | + { |
|
54 | 56 | return '[]'; |
55 | 57 | } |
56 | 58 | //Delimiters between rows and sub-arrays. |
@@ -60,15 +62,19 @@ discard block |
||
60 | 62 | $associated = array_diff_key($array, array_keys(array_keys($array))); |
61 | 63 | $result = []; |
62 | 64 | $innerIndent = 0; |
63 | - if (!empty($associated)) { |
|
64 | - foreach ($array as $key => $_) { |
|
65 | + if (!empty($associated)) |
|
66 | + { |
|
67 | + foreach ($array as $key => $_) |
|
68 | + { |
|
65 | 69 | //Based on biggest key length |
66 | 70 | $innerIndent = max(strlen(var_export($key, true)), $innerIndent); |
67 | 71 | } |
68 | 72 | } |
69 | - foreach ($array as $key => $value) { |
|
73 | + foreach ($array as $key => $value) |
|
74 | + { |
|
70 | 75 | $prefix = ''; |
71 | - if (!empty($associated)) { |
|
76 | + if (!empty($associated)) |
|
77 | + { |
|
72 | 78 | //Key prefix |
73 | 79 | $prefix = str_pad( |
74 | 80 | var_export($key, true), |
@@ -77,18 +83,21 @@ discard block |
||
77 | 83 | STR_PAD_RIGHT |
78 | 84 | ) . ' => '; |
79 | 85 | } |
80 | - if (!is_array($value)) { |
|
86 | + if (!is_array($value)) |
|
87 | + { |
|
81 | 88 | $result[] = $prefix . $this->packValue($value); |
82 | 89 | continue; |
83 | 90 | } |
84 | - if ($value === []) { |
|
91 | + if ($value === []) |
|
92 | + { |
|
85 | 93 | $result[] = $prefix . '[]'; |
86 | 94 | continue; |
87 | 95 | } |
88 | 96 | $subArray = $this->packArray($value, $level + 1); |
89 | 97 | $result[] = $prefix . "[{$subIndent}" . $subArray . "{$keyIndent}]"; |
90 | 98 | } |
91 | - if ($level !== 0) { |
|
99 | + if ($level !== 0) |
|
100 | + { |
|
92 | 101 | return $result ? implode(",{$keyIndent}", $result) : ''; |
93 | 102 | } |
94 | 103 | |
@@ -105,30 +114,37 @@ discard block |
||
105 | 114 | */ |
106 | 115 | protected function packValue($value): string |
107 | 116 | { |
108 | - if ($value instanceof DeclarationInterface) { |
|
117 | + if ($value instanceof DeclarationInterface) |
|
118 | + { |
|
109 | 119 | //No indentation here |
110 | 120 | return $value->render(); |
111 | 121 | } |
112 | 122 | |
113 | - if ($value === null) { |
|
123 | + if ($value === null) |
|
124 | + { |
|
114 | 125 | return 'null'; |
115 | 126 | } |
116 | 127 | |
117 | - if (is_bool($value)) { |
|
128 | + if (is_bool($value)) |
|
129 | + { |
|
118 | 130 | return ($value ? 'true' : 'false'); |
119 | 131 | } |
120 | 132 | |
121 | - if (is_object($value) && method_exists($value, '__set_state')) { |
|
133 | + if (is_object($value) && method_exists($value, '__set_state')) |
|
134 | + { |
|
122 | 135 | return '\\' . var_export($value, true); |
123 | 136 | } |
124 | 137 | |
125 | - if (!is_string($value) && !is_numeric($value)) { |
|
138 | + if (!is_string($value) && !is_numeric($value)) |
|
139 | + { |
|
126 | 140 | throw new SerializeException('Unable to pack non scalar value'); |
127 | 141 | } |
128 | 142 | |
129 | - if (is_string($value) && class_exists($value)) { |
|
143 | + if (is_string($value) && class_exists($value)) |
|
144 | + { |
|
130 | 145 | $reflection = new ReflectionClass($value); |
131 | - if ($value === $reflection->getName()) { |
|
146 | + if ($value === $reflection->getName()) |
|
147 | + { |
|
132 | 148 | return '\\' . $reflection->getName() . '::class'; |
133 | 149 | } |
134 | 150 | } |
@@ -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 => $_) { |
|
358 | + foreach ($this->traits as $class => $_){ |
|
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 => $_) { |
|
368 | + foreach ($this->traits as $class => $_) |
|
369 | + { |
|
359 | 370 | $lines[] = $this->addIndent("use {$class};", $indentLevel); |
360 | 371 | } |
361 | 372 |
@@ -45,7 +45,7 @@ |
||
45 | 45 | ], |
46 | 46 | ]); |
47 | 47 | |
48 | - foreach ($rules as $rule) { |
|
48 | + foreach ($rules as $rule){ |
|
49 | 49 | return $rule->getConditions(); |
50 | 50 | } |
51 | 51 |
@@ -45,7 +45,8 @@ |
||
45 | 45 | ], |
46 | 46 | ]); |
47 | 47 | |
48 | - foreach ($rules as $rule) { |
|
48 | + foreach ($rules as $rule) |
|
49 | + { |
|
49 | 50 | return $rule->getConditions(); |
50 | 51 | } |
51 | 52 |
@@ -167,12 +167,14 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function match(UriInterface $uri, array $defaults): ?array |
169 | 169 | { |
170 | - if (!$this->isCompiled()) { |
|
170 | + if (!$this->isCompiled()) |
|
171 | + { |
|
171 | 172 | $this->compile(); |
172 | 173 | } |
173 | 174 | |
174 | 175 | $matches = []; |
175 | - if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)) { |
|
176 | + if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)) |
|
177 | + { |
|
176 | 178 | return null; |
177 | 179 | } |
178 | 180 | |
@@ -190,7 +192,8 @@ discard block |
||
190 | 192 | */ |
191 | 193 | public function uri($parameters = [], array $defaults = []): UriInterface |
192 | 194 | { |
193 | - if (!$this->isCompiled()) { |
|
195 | + if (!$this->isCompiled()) |
|
196 | + { |
|
194 | 197 | $this->compile(); |
195 | 198 | } |
196 | 199 | |
@@ -200,8 +203,10 @@ discard block |
||
200 | 203 | $this->fetchOptions($parameters, $query) |
201 | 204 | ); |
202 | 205 | |
203 | - foreach ($this->constrains as $key => $_) { |
|
204 | - if (empty($parameters[$key])) { |
|
206 | + foreach ($this->constrains as $key => $_) |
|
207 | + { |
|
208 | + if (empty($parameters[$key])) |
|
209 | + { |
|
205 | 210 | throw new UriHandlerException("Unable to generate Uri, parameter `{$key}` is missing"); |
206 | 211 | } |
207 | 212 | } |
@@ -227,18 +232,23 @@ discard block |
||
227 | 232 | $allowed = array_keys($this->options); |
228 | 233 | |
229 | 234 | $result = []; |
230 | - foreach ($parameters as $key => $parameter) { |
|
231 | - if (is_numeric($key) && isset($allowed[$key])) { |
|
235 | + foreach ($parameters as $key => $parameter) |
|
236 | + { |
|
237 | + if (is_numeric($key) && isset($allowed[$key])) |
|
238 | + { |
|
232 | 239 | // this segment fetched keys from given parameters either by name or by position |
233 | 240 | $key = $allowed[$key]; |
234 | - } elseif (!array_key_exists($key, $this->options) && is_array($parameters)) { |
|
241 | + } |
|
242 | + elseif (!array_key_exists($key, $this->options) && is_array($parameters)) |
|
243 | + { |
|
235 | 244 | // all additional parameters given in array form can be glued to query string |
236 | 245 | $query[$key] = $parameter; |
237 | 246 | continue; |
238 | 247 | } |
239 | 248 | |
240 | 249 | //String must be normalized here |
241 | - if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)) { |
|
250 | + if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)) |
|
251 | + { |
|
242 | 252 | $result[$key] = $this->slugify->slugify($parameter); |
243 | 253 | continue; |
244 | 254 | } |
@@ -259,15 +269,20 @@ discard block |
||
259 | 269 | { |
260 | 270 | $path = $uri->getPath(); |
261 | 271 | |
262 | - if (empty($path) || $path[0] !== '/') { |
|
272 | + if (empty($path) || $path[0] !== '/') |
|
273 | + { |
|
263 | 274 | $path = '/' . $path; |
264 | 275 | } |
265 | 276 | |
266 | - if ($this->matchHost) { |
|
277 | + if ($this->matchHost) |
|
278 | + { |
|
267 | 279 | $uriString = $uri->getHost() . $path; |
268 | - } else { |
|
280 | + } |
|
281 | + else |
|
282 | + { |
|
269 | 283 | $uriString = substr($path, strlen($this->prefix)); |
270 | - if ($uriString === false) { |
|
284 | + if ($uriString === false) |
|
285 | + { |
|
271 | 286 | $uriString = ''; |
272 | 287 | } |
273 | 288 | } |
@@ -280,7 +295,8 @@ discard block |
||
280 | 295 | */ |
281 | 296 | private function compile(): void |
282 | 297 | { |
283 | - if ($this->pattern === null) { |
|
298 | + if ($this->pattern === null) |
|
299 | + { |
|
284 | 300 | throw new UriHandlerException('Unable to compile UriHandler, pattern is not set'); |
285 | 301 | } |
286 | 302 | |
@@ -288,14 +304,17 @@ discard block |
||
288 | 304 | $pattern = rtrim(ltrim($this->pattern, ':/'), '/'); |
289 | 305 | |
290 | 306 | // correct [/ first occurrence] |
291 | - if (strpos($pattern, '[/') === 0) { |
|
307 | + if (strpos($pattern, '[/') === 0) |
|
308 | + { |
|
292 | 309 | $pattern = '[' . substr($pattern, 2); |
293 | 310 | } |
294 | 311 | |
295 | - if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) { |
|
312 | + if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) |
|
313 | + { |
|
296 | 314 | $variables = array_combine($matches[1], $matches[2]); |
297 | 315 | |
298 | - foreach ($variables as $key => $segment) { |
|
316 | + foreach ($variables as $key => $segment) |
|
317 | + { |
|
299 | 318 | $segment = $this->prepareSegment($key, $segment); |
300 | 319 | $replaces["<$key>"] = "(?P<$key>$segment)"; |
301 | 320 | $options[] = $key; |
@@ -305,13 +324,16 @@ discard block |
||
305 | 324 | $template = preg_replace('/<(\w+):?.*?>/', '<\1>', $pattern); |
306 | 325 | $options = array_fill_keys($options, null); |
307 | 326 | |
308 | - foreach ($this->constrains as $key => $value) { |
|
309 | - if ($value instanceof Autofill) { |
|
327 | + foreach ($this->constrains as $key => $value) |
|
328 | + { |
|
329 | + if ($value instanceof Autofill) |
|
330 | + { |
|
310 | 331 | // only forces value replacement, not required to be presented as parameter |
311 | 332 | continue; |
312 | 333 | } |
313 | 334 | |
314 | - if (!array_key_exists($key, $options) && !isset($this->defaults[$key])) { |
|
335 | + if (!array_key_exists($key, $options) && !isset($this->defaults[$key])) |
|
336 | + { |
|
315 | 337 | throw new ConstrainException( |
316 | 338 | sprintf( |
317 | 339 | 'Route `%s` does not define routing parameter `<%s>`.', |
@@ -337,7 +359,8 @@ discard block |
||
337 | 359 | private function interpolate(string $string, array $values): string |
338 | 360 | { |
339 | 361 | $replaces = []; |
340 | - foreach ($values as $key => $value) { |
|
362 | + foreach ($values as $key => $value) |
|
363 | + { |
|
341 | 364 | $value = (is_array($value) || $value instanceof \Closure) ? '' : $value; |
342 | 365 | $replaces["<{$key}>"] = is_object($value) ? (string)$value : $value; |
343 | 366 | } |
@@ -354,15 +377,18 @@ discard block |
||
354 | 377 | */ |
355 | 378 | private function prepareSegment(string $name, string $segment): string |
356 | 379 | { |
357 | - if ($segment !== '') { |
|
380 | + if ($segment !== '') |
|
381 | + { |
|
358 | 382 | return self::SEGMENT_TYPES[$segment] ?? $segment; |
359 | 383 | } |
360 | 384 | |
361 | - if (!isset($this->constrains[$name])) { |
|
385 | + if (!isset($this->constrains[$name])) |
|
386 | + { |
|
362 | 387 | return self::DEFAULT_SEGMENT; |
363 | 388 | } |
364 | 389 | |
365 | - if (is_array($this->constrains[$name])) { |
|
390 | + if (is_array($this->constrains[$name])) |
|
391 | + { |
|
366 | 392 | $values = array_map([$this, 'filterSegment'], $this->constrains[$name]); |
367 | 393 | |
368 | 394 | return implode('|', $values); |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | 'integer' => '\d+', |
33 | 33 | 'uuid' => '[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}', |
34 | 34 | ]; |
35 | - private const URI_FIXERS = [ |
|
35 | + private const URI_FIXERS = [ |
|
36 | 36 | '[]' => '', |
37 | 37 | '[/]' => '', |
38 | 38 | '[' => '', |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | public function __construct( |
79 | 79 | UriFactoryInterface $uriFactory, |
80 | 80 | SlugifyInterface $slugify = null |
81 | - ) { |
|
81 | + ){ |
|
82 | 82 | $this->uriFactory = $uriFactory; |
83 | 83 | $this->slugify = $slugify ?? new Slugify(); |
84 | 84 | } |
@@ -167,12 +167,12 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function match(UriInterface $uri, array $defaults): ?array |
169 | 169 | { |
170 | - if (!$this->isCompiled()) { |
|
170 | + if (!$this->isCompiled()){ |
|
171 | 171 | $this->compile(); |
172 | 172 | } |
173 | 173 | |
174 | 174 | $matches = []; |
175 | - if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)) { |
|
175 | + if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)){ |
|
176 | 176 | return null; |
177 | 177 | } |
178 | 178 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public function uri($parameters = [], array $defaults = []): UriInterface |
192 | 192 | { |
193 | - if (!$this->isCompiled()) { |
|
193 | + if (!$this->isCompiled()){ |
|
194 | 194 | $this->compile(); |
195 | 195 | } |
196 | 196 | |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | $this->fetchOptions($parameters, $query) |
201 | 201 | ); |
202 | 202 | |
203 | - foreach ($this->constrains as $key => $_) { |
|
204 | - if (empty($parameters[$key])) { |
|
203 | + foreach ($this->constrains as $key => $_){ |
|
204 | + if (empty($parameters[$key])){ |
|
205 | 205 | throw new UriHandlerException("Unable to generate Uri, parameter `{$key}` is missing"); |
206 | 206 | } |
207 | 207 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $path = $this->interpolate($this->template, $parameters); |
211 | 211 | |
212 | 212 | //Uri with added prefix |
213 | - $uri = $this->uriFactory->createUri(($this->matchHost ? '' : $this->prefix) . trim($path, '/')); |
|
213 | + $uri = $this->uriFactory->createUri(($this->matchHost ? '' : $this->prefix).trim($path, '/')); |
|
214 | 214 | |
215 | 215 | return empty($query) ? $uri : $uri->withQuery(http_build_query($query)); |
216 | 216 | } |
@@ -227,18 +227,18 @@ discard block |
||
227 | 227 | $allowed = array_keys($this->options); |
228 | 228 | |
229 | 229 | $result = []; |
230 | - foreach ($parameters as $key => $parameter) { |
|
231 | - if (is_numeric($key) && isset($allowed[$key])) { |
|
230 | + foreach ($parameters as $key => $parameter){ |
|
231 | + if (is_numeric($key) && isset($allowed[$key])){ |
|
232 | 232 | // this segment fetched keys from given parameters either by name or by position |
233 | 233 | $key = $allowed[$key]; |
234 | - } elseif (!array_key_exists($key, $this->options) && is_array($parameters)) { |
|
234 | + } elseif (!array_key_exists($key, $this->options) && is_array($parameters)){ |
|
235 | 235 | // all additional parameters given in array form can be glued to query string |
236 | 236 | $query[$key] = $parameter; |
237 | 237 | continue; |
238 | 238 | } |
239 | 239 | |
240 | 240 | //String must be normalized here |
241 | - if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)) { |
|
241 | + if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)){ |
|
242 | 242 | $result[$key] = $this->slugify->slugify($parameter); |
243 | 243 | continue; |
244 | 244 | } |
@@ -259,15 +259,15 @@ discard block |
||
259 | 259 | { |
260 | 260 | $path = $uri->getPath(); |
261 | 261 | |
262 | - if (empty($path) || $path[0] !== '/') { |
|
263 | - $path = '/' . $path; |
|
262 | + if (empty($path) || $path[0] !== '/'){ |
|
263 | + $path = '/'.$path; |
|
264 | 264 | } |
265 | 265 | |
266 | - if ($this->matchHost) { |
|
267 | - $uriString = $uri->getHost() . $path; |
|
268 | - } else { |
|
266 | + if ($this->matchHost){ |
|
267 | + $uriString = $uri->getHost().$path; |
|
268 | + }else{ |
|
269 | 269 | $uriString = substr($path, strlen($this->prefix)); |
270 | - if ($uriString === false) { |
|
270 | + if ($uriString === false){ |
|
271 | 271 | $uriString = ''; |
272 | 272 | } |
273 | 273 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | */ |
281 | 281 | private function compile(): void |
282 | 282 | { |
283 | - if ($this->pattern === null) { |
|
283 | + if ($this->pattern === null){ |
|
284 | 284 | throw new UriHandlerException('Unable to compile UriHandler, pattern is not set'); |
285 | 285 | } |
286 | 286 | |
@@ -288,14 +288,14 @@ discard block |
||
288 | 288 | $pattern = rtrim(ltrim($this->pattern, ':/'), '/'); |
289 | 289 | |
290 | 290 | // correct [/ first occurrence] |
291 | - if (strpos($pattern, '[/') === 0) { |
|
292 | - $pattern = '[' . substr($pattern, 2); |
|
291 | + if (strpos($pattern, '[/') === 0){ |
|
292 | + $pattern = '['.substr($pattern, 2); |
|
293 | 293 | } |
294 | 294 | |
295 | - if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) { |
|
295 | + if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)){ |
|
296 | 296 | $variables = array_combine($matches[1], $matches[2]); |
297 | 297 | |
298 | - foreach ($variables as $key => $segment) { |
|
298 | + foreach ($variables as $key => $segment){ |
|
299 | 299 | $segment = $this->prepareSegment($key, $segment); |
300 | 300 | $replaces["<$key>"] = "(?P<$key>$segment)"; |
301 | 301 | $options[] = $key; |
@@ -305,13 +305,13 @@ discard block |
||
305 | 305 | $template = preg_replace('/<(\w+):?.*?>/', '<\1>', $pattern); |
306 | 306 | $options = array_fill_keys($options, null); |
307 | 307 | |
308 | - foreach ($this->constrains as $key => $value) { |
|
309 | - if ($value instanceof Autofill) { |
|
308 | + foreach ($this->constrains as $key => $value){ |
|
309 | + if ($value instanceof Autofill){ |
|
310 | 310 | // only forces value replacement, not required to be presented as parameter |
311 | 311 | continue; |
312 | 312 | } |
313 | 313 | |
314 | - if (!array_key_exists($key, $options) && !isset($this->defaults[$key])) { |
|
314 | + if (!array_key_exists($key, $options) && !isset($this->defaults[$key])){ |
|
315 | 315 | throw new ConstrainException( |
316 | 316 | sprintf( |
317 | 317 | 'Route `%s` does not define routing parameter `<%s>`.', |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | } |
323 | 323 | } |
324 | 324 | |
325 | - $this->compiled = '/^' . strtr($template, $replaces + self::PATTERN_REPLACES) . '$/iu'; |
|
325 | + $this->compiled = '/^'.strtr($template, $replaces + self::PATTERN_REPLACES).'$/iu'; |
|
326 | 326 | $this->template = stripslashes(str_replace('?', '', $template)); |
327 | 327 | $this->options = $options; |
328 | 328 | } |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | private function interpolate(string $string, array $values): string |
338 | 338 | { |
339 | 339 | $replaces = []; |
340 | - foreach ($values as $key => $value) { |
|
340 | + foreach ($values as $key => $value){ |
|
341 | 341 | $value = (is_array($value) || $value instanceof \Closure) ? '' : $value; |
342 | 342 | $replaces["<{$key}>"] = is_object($value) ? (string)$value : $value; |
343 | 343 | } |
@@ -354,15 +354,15 @@ discard block |
||
354 | 354 | */ |
355 | 355 | private function prepareSegment(string $name, string $segment): string |
356 | 356 | { |
357 | - if ($segment !== '') { |
|
357 | + if ($segment !== ''){ |
|
358 | 358 | return self::SEGMENT_TYPES[$segment] ?? $segment; |
359 | 359 | } |
360 | 360 | |
361 | - if (!isset($this->constrains[$name])) { |
|
361 | + if (!isset($this->constrains[$name])){ |
|
362 | 362 | return self::DEFAULT_SEGMENT; |
363 | 363 | } |
364 | 364 | |
365 | - if (is_array($this->constrains[$name])) { |
|
365 | + if (is_array($this->constrains[$name])){ |
|
366 | 366 | $values = array_map([$this, 'filterSegment'], $this->constrains[$name]); |
367 | 367 | |
368 | 368 | return implode('|', $values); |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function withinContext(?Context $ctx, callable $body): void |
39 | 39 | { |
40 | - if ($ctx === null || $ctx->getPath() === null) { |
|
40 | + if ($ctx === null || $ctx->getPath() === null){ |
|
41 | 41 | $body($this); |
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | - try { |
|
45 | + try{ |
|
46 | 46 | $this->parent = Location::fromContext($ctx, $this->parent); |
47 | 47 | $body($this); |
48 | - } finally { |
|
48 | + }finally{ |
|
49 | 49 | $this->parent = $this->parent->parent; |
50 | 50 | } |
51 | 51 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function push(string $content, Context $ctx = null): void |
58 | 58 | { |
59 | - if ($ctx !== null && $ctx->getPath() !== null) { |
|
59 | + if ($ctx !== null && $ctx->getPath() !== null){ |
|
60 | 60 | $this->locations[strlen($this->content)] = Location::fromContext($ctx, $this->parent); |
61 | 61 | } |
62 | 62 | |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | $paths = []; |
82 | 82 | |
83 | 83 | // We can scan top level only |
84 | - foreach ($this->locations as $loc) { |
|
85 | - if (!in_array($loc->path, $paths, true)) { |
|
84 | + foreach ($this->locations as $loc){ |
|
85 | + if (!in_array($loc->path, $paths, true)){ |
|
86 | 86 | $paths[] = $loc->path; |
87 | 87 | } |
88 | 88 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | { |
101 | 101 | $locations = []; |
102 | 102 | |
103 | - foreach ($this->locations as $offset => $location) { |
|
103 | + foreach ($this->locations as $offset => $location){ |
|
104 | 104 | $locations[$offset] = $location; |
105 | 105 | } |
106 | 106 |
@@ -37,15 +37,19 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function withinContext(?Context $ctx, callable $body): void |
39 | 39 | { |
40 | - if ($ctx === null || $ctx->getPath() === null) { |
|
40 | + if ($ctx === null || $ctx->getPath() === null) |
|
41 | + { |
|
41 | 42 | $body($this); |
42 | 43 | return; |
43 | 44 | } |
44 | 45 | |
45 | - try { |
|
46 | + try |
|
47 | + { |
|
46 | 48 | $this->parent = Location::fromContext($ctx, $this->parent); |
47 | 49 | $body($this); |
48 | - } finally { |
|
50 | + } |
|
51 | + finally |
|
52 | + { |
|
49 | 53 | $this->parent = $this->parent->parent; |
50 | 54 | } |
51 | 55 | } |
@@ -56,7 +60,8 @@ discard block |
||
56 | 60 | */ |
57 | 61 | public function push(string $content, Context $ctx = null): void |
58 | 62 | { |
59 | - if ($ctx !== null && $ctx->getPath() !== null) { |
|
63 | + if ($ctx !== null && $ctx->getPath() !== null) |
|
64 | + { |
|
60 | 65 | $this->locations[strlen($this->content)] = Location::fromContext($ctx, $this->parent); |
61 | 66 | } |
62 | 67 | |
@@ -81,8 +86,10 @@ discard block |
||
81 | 86 | $paths = []; |
82 | 87 | |
83 | 88 | // We can scan top level only |
84 | - foreach ($this->locations as $loc) { |
|
85 | - if (!in_array($loc->path, $paths, true)) { |
|
89 | + foreach ($this->locations as $loc) |
|
90 | + { |
|
91 | + if (!in_array($loc->path, $paths, true)) |
|
92 | + { |
|
86 | 93 | $paths[] = $loc->path; |
87 | 94 | } |
88 | 95 | } |
@@ -100,7 +107,8 @@ discard block |
||
100 | 107 | { |
101 | 108 | $locations = []; |
102 | 109 | |
103 | - foreach ($this->locations as $offset => $location) { |
|
110 | + foreach ($this->locations as $offset => $location) |
|
111 | + { |
|
104 | 112 | $locations[$offset] = $location; |
105 | 113 | } |
106 | 114 |
@@ -43,16 +43,16 @@ |
||
43 | 43 | if ( |
44 | 44 | !$node instanceof PHP |
45 | 45 | || strpos($node->content, self::PHP_MARCO_EXISTS_FUNCTION) === false |
46 | - ) { |
|
46 | + ){ |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - if ($node->getContext()->getPath() !== $this->path) { |
|
50 | + if ($node->getContext()->getPath() !== $this->path){ |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
54 | 54 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
55 | - foreach ($exists->getBlocks() as $name => $_) { |
|
55 | + foreach ($exists->getBlocks() as $name => $_){ |
|
56 | 56 | // do not leak to parent template |
57 | 57 | $exists->set($name, 'false'); |
58 | 58 | } |
@@ -47,12 +47,14 @@ |
||
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - if ($node->getContext()->getPath() !== $this->path) { |
|
50 | + if ($node->getContext()->getPath() !== $this->path) |
|
51 | + { |
|
51 | 52 | return; |
52 | 53 | } |
53 | 54 | |
54 | 55 | $exists = new PHPMixin($node->tokens, self::PHP_MARCO_EXISTS_FUNCTION); |
55 | - foreach ($exists->getBlocks() as $name => $_) { |
|
56 | + foreach ($exists->getBlocks() as $name => $_) |
|
57 | + { |
|
56 | 58 | // do not leak to parent template |
57 | 59 | $exists->set($name, 'false'); |
58 | 60 | } |
@@ -78,17 +78,17 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function leaveNode($node, VisitorContext $ctx) |
80 | 80 | { |
81 | - if ($node instanceof Output) { |
|
81 | + if ($node instanceof Output){ |
|
82 | 82 | return $this->output($node, $ctx); |
83 | 83 | } |
84 | 84 | |
85 | - if ($node instanceof Directive) { |
|
85 | + if ($node instanceof Directive){ |
|
86 | 86 | return $this->directive($node); |
87 | 87 | } |
88 | 88 | |
89 | - if ($node instanceof Template) { |
|
89 | + if ($node instanceof Template){ |
|
90 | 90 | $extendsTag = $node->getAttribute(ExtendsParent::class); |
91 | - if ($extendsTag instanceof Tag) { |
|
91 | + if ($extendsTag instanceof Tag){ |
|
92 | 92 | $extendsTag->attrs = $this->traverser->traverse($extendsTag->attrs); |
93 | 93 | } |
94 | 94 | } |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | */ |
103 | 103 | private function directive(Directive $node): PHP |
104 | 104 | { |
105 | - foreach ($this->directives as $renderer) { |
|
105 | + foreach ($this->directives as $renderer){ |
|
106 | 106 | $result = $renderer->render($node); |
107 | - if ($result !== null) { |
|
107 | + if ($result !== null){ |
|
108 | 108 | return new PHP($result, token_get_all($result), $node->getContext()); |
109 | 109 | } |
110 | 110 | } |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | * In future this method can support context aware escaping based on tag location. |
127 | 127 | */ |
128 | 128 | |
129 | - if ($node->rawOutput) { |
|
129 | + if ($node->rawOutput){ |
|
130 | 130 | $result = sprintf('<?php echo %s; ?>', trim($node->body)); |
131 | - } else { |
|
131 | + }else{ |
|
132 | 132 | $filter = $node->filter ?? $this->getFilterContext($ctx); |
133 | 133 | |
134 | 134 | $result = sprintf("<?php echo {$filter}; ?>", trim($node->body)); |
@@ -150,22 +150,22 @@ discard block |
||
150 | 150 | // only "interesting" nodes |
151 | 151 | $context = []; |
152 | 152 | |
153 | - foreach (array_reverse($ctx->getScope()) as $node) { |
|
154 | - if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) { |
|
153 | + foreach (array_reverse($ctx->getScope()) as $node){ |
|
154 | + if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim){ |
|
155 | 155 | $context[] = $node; |
156 | 156 | } |
157 | 157 | |
158 | - if (count($context) === 2) { |
|
158 | + if (count($context) === 2){ |
|
159 | 159 | break; |
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | - if (count($context) !== 2) { |
|
163 | + if (count($context) !== 2){ |
|
164 | 164 | return $this->defaultFilter; |
165 | 165 | } |
166 | 166 | |
167 | 167 | // php {{ }} in javascript code (variable passing), use {! !} to bypass the filter |
168 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') { |
|
168 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script'){ |
|
169 | 169 | return sprintf( |
170 | 170 | 'json_encode(%s, %s, %s)', |
171 | 171 | '%s', |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | // in on* and other attributes |
178 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') { |
|
178 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style'){ |
|
179 | 179 | return sprintf("'%s', %s, '%s'", '"', $this->defaultFilter, '"'); |
180 | 180 | } |
181 | 181 |
@@ -78,17 +78,21 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function leaveNode($node, VisitorContext $ctx) |
80 | 80 | { |
81 | - if ($node instanceof Output) { |
|
81 | + if ($node instanceof Output) |
|
82 | + { |
|
82 | 83 | return $this->output($node, $ctx); |
83 | 84 | } |
84 | 85 | |
85 | - if ($node instanceof Directive) { |
|
86 | + if ($node instanceof Directive) |
|
87 | + { |
|
86 | 88 | return $this->directive($node); |
87 | 89 | } |
88 | 90 | |
89 | - if ($node instanceof Template) { |
|
91 | + if ($node instanceof Template) |
|
92 | + { |
|
90 | 93 | $extendsTag = $node->getAttribute(ExtendsParent::class); |
91 | - if ($extendsTag instanceof Tag) { |
|
94 | + if ($extendsTag instanceof Tag) |
|
95 | + { |
|
92 | 96 | $extendsTag->attrs = $this->traverser->traverse($extendsTag->attrs); |
93 | 97 | } |
94 | 98 | } |
@@ -102,9 +106,11 @@ discard block |
||
102 | 106 | */ |
103 | 107 | private function directive(Directive $node): PHP |
104 | 108 | { |
105 | - foreach ($this->directives as $renderer) { |
|
109 | + foreach ($this->directives as $renderer) |
|
110 | + { |
|
106 | 111 | $result = $renderer->render($node); |
107 | - if ($result !== null) { |
|
112 | + if ($result !== null) |
|
113 | + { |
|
108 | 114 | return new PHP($result, token_get_all($result), $node->getContext()); |
109 | 115 | } |
110 | 116 | } |
@@ -126,9 +132,12 @@ discard block |
||
126 | 132 | * In future this method can support context aware escaping based on tag location. |
127 | 133 | */ |
128 | 134 | |
129 | - if ($node->rawOutput) { |
|
135 | + if ($node->rawOutput) |
|
136 | + { |
|
130 | 137 | $result = sprintf('<?php echo %s; ?>', trim($node->body)); |
131 | - } else { |
|
138 | + } |
|
139 | + else |
|
140 | + { |
|
132 | 141 | $filter = $node->filter ?? $this->getFilterContext($ctx); |
133 | 142 | |
134 | 143 | $result = sprintf("<?php echo {$filter}; ?>", trim($node->body)); |
@@ -150,22 +159,27 @@ discard block |
||
150 | 159 | // only "interesting" nodes |
151 | 160 | $context = []; |
152 | 161 | |
153 | - foreach (array_reverse($ctx->getScope()) as $node) { |
|
154 | - if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) { |
|
162 | + foreach (array_reverse($ctx->getScope()) as $node) |
|
163 | + { |
|
164 | + if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) |
|
165 | + { |
|
155 | 166 | $context[] = $node; |
156 | 167 | } |
157 | 168 | |
158 | - if (count($context) === 2) { |
|
169 | + if (count($context) === 2) |
|
170 | + { |
|
159 | 171 | break; |
160 | 172 | } |
161 | 173 | } |
162 | 174 | |
163 | - if (count($context) !== 2) { |
|
175 | + if (count($context) !== 2) |
|
176 | + { |
|
164 | 177 | return $this->defaultFilter; |
165 | 178 | } |
166 | 179 | |
167 | 180 | // php {{ }} in javascript code (variable passing), use {! !} to bypass the filter |
168 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') { |
|
181 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') |
|
182 | + { |
|
169 | 183 | return sprintf( |
170 | 184 | 'json_encode(%s, %s, %s)', |
171 | 185 | '%s', |
@@ -175,7 +189,8 @@ discard block |
||
175 | 189 | } |
176 | 190 | |
177 | 191 | // in on* and other attributes |
178 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') { |
|
192 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') |
|
193 | + { |
|
179 | 194 | return sprintf("'%s', %s, '%s'", '"', $this->defaultFilter, '"'); |
180 | 195 | } |
181 | 196 |