@@ -39,24 +39,24 @@ |
||
39 | 39 | */ |
40 | 40 | private function renderTrace(array $trace, int $verbosity): \Generator |
41 | 41 | { |
42 | - foreach ($trace as $item) { |
|
42 | + foreach ($trace as $item){ |
|
43 | 43 | $result = []; |
44 | 44 | |
45 | - if (isset($item['class'])) { |
|
45 | + if (isset($item['class'])){ |
|
46 | 46 | $result['function'] = sprintf( |
47 | 47 | '%s%s%s()', |
48 | 48 | $item['class'], |
49 | 49 | $item['type'], |
50 | 50 | $item['function'] |
51 | 51 | ); |
52 | - } else { |
|
52 | + }else{ |
|
53 | 53 | $result['function'] = sprintf( |
54 | 54 | '%s()', |
55 | 55 | $item['function'] |
56 | 56 | ); |
57 | 57 | } |
58 | 58 | |
59 | - if ($verbosity >= self::VERBOSITY_VERBOSE && isset($item['file'])) { |
|
59 | + if ($verbosity >= self::VERBOSITY_VERBOSE && isset($item['file'])){ |
|
60 | 60 | $result['at'] = [ |
61 | 61 | 'file' => $item['file'] ?? null, |
62 | 62 | 'line' => $item['line'] ?? null, |
@@ -39,24 +39,29 @@ |
||
39 | 39 | */ |
40 | 40 | private function renderTrace(array $trace, int $verbosity): \Generator |
41 | 41 | { |
42 | - foreach ($trace as $item) { |
|
42 | + foreach ($trace as $item) |
|
43 | + { |
|
43 | 44 | $result = []; |
44 | 45 | |
45 | - if (isset($item['class'])) { |
|
46 | + if (isset($item['class'])) |
|
47 | + { |
|
46 | 48 | $result['function'] = sprintf( |
47 | 49 | '%s%s%s()', |
48 | 50 | $item['class'], |
49 | 51 | $item['type'], |
50 | 52 | $item['function'] |
51 | 53 | ); |
52 | - } else { |
|
54 | + } |
|
55 | + else |
|
56 | + { |
|
53 | 57 | $result['function'] = sprintf( |
54 | 58 | '%s()', |
55 | 59 | $item['function'] |
56 | 60 | ); |
57 | 61 | } |
58 | 62 | |
59 | - if ($verbosity >= self::VERBOSITY_VERBOSE && isset($item['file'])) { |
|
63 | + if ($verbosity >= self::VERBOSITY_VERBOSE && isset($item['file'])) |
|
64 | + { |
|
60 | 65 | $result['at'] = [ |
61 | 66 | 'file' => $item['file'] ?? null, |
62 | 67 | 'line' => $item['line'] ?? null, |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | T_VARIABLE, |
149 | 149 | ], |
150 | 150 | 'color: #E6D100;' => [ |
151 | - '->' . T_STRING, |
|
152 | - '::' . T_STRING, |
|
151 | + '->'.T_STRING, |
|
152 | + '::'.T_STRING, |
|
153 | 153 | ], |
154 | 154 | ]; |
155 | 155 | |
@@ -186,12 +186,12 @@ discard block |
||
186 | 186 | { |
187 | 187 | $style = $this->getStyle($token, $previous); |
188 | 188 | |
189 | - if (strpos($token[1], "\n") === false) { |
|
189 | + if (strpos($token[1], "\n") === false){ |
|
190 | 190 | return sprintf($this->templates['token'], $style, htmlspecialchars($token[1])); |
191 | 191 | } |
192 | 192 | |
193 | 193 | $lines = []; |
194 | - foreach (explode("\n", $token[1]) as $line) { |
|
194 | + foreach (explode("\n", $token[1]) as $line){ |
|
195 | 195 | $lines[] = sprintf($this->templates['token'], $style, htmlspecialchars($line)); |
196 | 196 | } |
197 | 197 | |
@@ -215,16 +215,16 @@ discard block |
||
215 | 215 | */ |
216 | 216 | private function getStyle(array $token, array $previous): string |
217 | 217 | { |
218 | - if (!empty($previous)) { |
|
219 | - foreach ($this->style as $style => $tokens) { |
|
220 | - if (in_array($previous[1] . $token[0], $tokens)) { |
|
218 | + if (!empty($previous)){ |
|
219 | + foreach ($this->style as $style => $tokens){ |
|
220 | + if (in_array($previous[1].$token[0], $tokens)){ |
|
221 | 221 | return $style; |
222 | 222 | } |
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
226 | - foreach ($this->style as $style => $tokens) { |
|
227 | - if (in_array($token[0], $tokens)) { |
|
226 | + foreach ($this->style as $style => $tokens){ |
|
227 | + if (in_array($token[0], $tokens)){ |
|
228 | 228 | return $style; |
229 | 229 | } |
230 | 230 | } |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | { |
22 | 22 | /** @var array */ |
23 | 23 | protected $templates = [ |
24 | - 'token' => '%s%s' . Color::RESET, |
|
25 | - 'line' => Color::LIGHT_CYAN . ' %s ' . Color::RESET . " %s\n", |
|
26 | - 'active' => Color::BG_RED . ' ' . Color::LIGHT_WHITE . '%s ' . Color::RESET . " %s\n", |
|
24 | + 'token' => '%s%s'.Color::RESET, |
|
25 | + 'line' => Color::LIGHT_CYAN.' %s '.Color::RESET." %s\n", |
|
26 | + 'active' => Color::BG_RED.' '.Color::LIGHT_WHITE.'%s '.Color::RESET." %s\n", |
|
27 | 27 | ]; |
28 | 28 | |
29 | 29 | /** @var array */ |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | T_VARIABLE, |
88 | 88 | ], |
89 | 89 | Color::LIGHT_YELLOW => [ |
90 | - '->' . T_STRING, |
|
91 | - '::' . T_STRING, |
|
90 | + '->'.T_STRING, |
|
91 | + '::'.T_STRING, |
|
92 | 92 | ], |
93 | 93 | ]; |
94 | 94 | |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | { |
100 | 100 | $style = $this->getStyle($token, $previous); |
101 | 101 | |
102 | - if (strpos($token[1], "\n") === false) { |
|
102 | + if (strpos($token[1], "\n") === false){ |
|
103 | 103 | return sprintf($this->templates['token'], $style, $token[1]); |
104 | 104 | } |
105 | 105 | |
106 | 106 | $lines = []; |
107 | - foreach (explode("\n", $token[1]) as $line) { |
|
107 | + foreach (explode("\n", $token[1]) as $line){ |
|
108 | 108 | $lines[] = sprintf($this->templates['token'], $style, $line); |
109 | 109 | } |
110 | 110 | |
@@ -132,16 +132,16 @@ discard block |
||
132 | 132 | */ |
133 | 133 | private function getStyle(array $token, array $previous): string |
134 | 134 | { |
135 | - if (!empty($previous)) { |
|
136 | - foreach ($this->style as $style => $tokens) { |
|
137 | - if (in_array($previous[1] . $token[0], $tokens)) { |
|
135 | + if (!empty($previous)){ |
|
136 | + foreach ($this->style as $style => $tokens){ |
|
137 | + if (in_array($previous[1].$token[0], $tokens)){ |
|
138 | 138 | return $style; |
139 | 139 | } |
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - foreach ($this->style as $style => $tokens) { |
|
144 | - if (in_array($token[0], $tokens)) { |
|
143 | + foreach ($this->style as $style => $tokens){ |
|
144 | + if (in_array($token[0], $tokens)){ |
|
145 | 145 | return $style; |
146 | 146 | } |
147 | 147 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | protected function getStacktrace(\Throwable $e): array |
34 | 34 | { |
35 | 35 | $stacktrace = $e->getTrace(); |
36 | - if (empty($stacktrace)) { |
|
36 | + if (empty($stacktrace)){ |
|
37 | 37 | return []; |
38 | 38 | } |
39 | 39 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | 'line' => $e->getLine(), |
44 | 44 | ] + $stacktrace[0]; |
45 | 45 | |
46 | - if ($stacktrace[0] != $header) { |
|
46 | + if ($stacktrace[0] != $header){ |
|
47 | 47 | array_unshift($stacktrace, $header); |
48 | 48 | } |
49 | 49 |
@@ -33,7 +33,8 @@ discard block |
||
33 | 33 | protected function getStacktrace(\Throwable $e): array |
34 | 34 | { |
35 | 35 | $stacktrace = $e->getTrace(); |
36 | - if (empty($stacktrace)) { |
|
36 | + if (empty($stacktrace)) |
|
37 | + { |
|
37 | 38 | return []; |
38 | 39 | } |
39 | 40 | |
@@ -43,7 +44,8 @@ discard block |
||
43 | 44 | 'line' => $e->getLine(), |
44 | 45 | ] + $stacktrace[0]; |
45 | 46 | |
46 | - if ($stacktrace[0] != $header) { |
|
47 | + if ($stacktrace[0] != $header) |
|
48 | + { |
|
47 | 49 | array_unshift($stacktrace, $header); |
48 | 50 | } |
49 | 51 |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | $this->style = $style; |
51 | 51 | $this->dumper = new Dumper(); |
52 | 52 | |
53 | - if ($style == self::INVERTED) { |
|
53 | + if ($style == self::INVERTED){ |
|
54 | 54 | $this->renderer = new HtmlRenderer(HtmlRenderer::INVERTED); |
55 | 55 | $this->highlighter = new Highlighter(new HtmlStyle(HtmlStyle::INVERTED)); |
56 | - } else { |
|
56 | + }else{ |
|
57 | 57 | $this->renderer = new HtmlRenderer(HtmlRenderer::DEFAULT); |
58 | 58 | $this->highlighter = new Highlighter(new HtmlStyle(HtmlStyle::DEFAULT)); |
59 | 59 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | 'message' => $this->getMessage($e), |
83 | 83 | 'exception' => $e, |
84 | 84 | 'valueWrapper' => new ValueWrapper($this->dumper, $this->renderer, $verbosity), |
85 | - 'style' => $this->render('styles/' . $this->style), |
|
85 | + 'style' => $this->render('styles/'.$this->style), |
|
86 | 86 | 'footer' => $this->render('partials/footer'), |
87 | 87 | 'variables' => '', |
88 | 88 | 'logs' => '', |
@@ -105,20 +105,20 @@ discard block |
||
105 | 105 | 'valueWrapper' => $options['valueWrapper'], |
106 | 106 | ]); |
107 | 107 | |
108 | - if ($this->state !== null) { |
|
109 | - if ($this->state->getTags() !== []) { |
|
108 | + if ($this->state !== null){ |
|
109 | + if ($this->state->getTags() !== []){ |
|
110 | 110 | $options['tags'] = $this->render('partials/tags', [ |
111 | 111 | 'tags' => $this->state->getTags(), |
112 | 112 | ]); |
113 | 113 | } |
114 | 114 | |
115 | - if ($this->state->getLogEvents() !== []) { |
|
115 | + if ($this->state->getLogEvents() !== []){ |
|
116 | 116 | $options['logs'] = $this->render('partials/logs', [ |
117 | 117 | 'logEvents' => $this->state->getLogEvents(), |
118 | 118 | ]); |
119 | 119 | } |
120 | 120 | |
121 | - if ($this->state->getVariables() !== []) { |
|
121 | + if ($this->state->getVariables() !== []){ |
|
122 | 122 | $options['variables'] = $this->render('partials/variables', [ |
123 | 123 | 'variables' => $this->state->getVariables(), |
124 | 124 | ]); |
@@ -50,10 +50,13 @@ discard block |
||
50 | 50 | $this->style = $style; |
51 | 51 | $this->dumper = new Dumper(); |
52 | 52 | |
53 | - if ($style == self::INVERTED) { |
|
53 | + if ($style == self::INVERTED) |
|
54 | + { |
|
54 | 55 | $this->renderer = new HtmlRenderer(HtmlRenderer::INVERTED); |
55 | 56 | $this->highlighter = new Highlighter(new HtmlStyle(HtmlStyle::INVERTED)); |
56 | - } else { |
|
57 | + } |
|
58 | + else |
|
59 | + { |
|
57 | 60 | $this->renderer = new HtmlRenderer(HtmlRenderer::DEFAULT); |
58 | 61 | $this->highlighter = new Highlighter(new HtmlStyle(HtmlStyle::DEFAULT)); |
59 | 62 | } |
@@ -105,20 +108,24 @@ discard block |
||
105 | 108 | 'valueWrapper' => $options['valueWrapper'], |
106 | 109 | ]); |
107 | 110 | |
108 | - if ($this->state !== null) { |
|
109 | - if ($this->state->getTags() !== []) { |
|
111 | + if ($this->state !== null) |
|
112 | + { |
|
113 | + if ($this->state->getTags() !== []) |
|
114 | + { |
|
110 | 115 | $options['tags'] = $this->render('partials/tags', [ |
111 | 116 | 'tags' => $this->state->getTags(), |
112 | 117 | ]); |
113 | 118 | } |
114 | 119 | |
115 | - if ($this->state->getLogEvents() !== []) { |
|
120 | + if ($this->state->getLogEvents() !== []) |
|
121 | + { |
|
116 | 122 | $options['logs'] = $this->render('partials/logs', [ |
117 | 123 | 'logEvents' => $this->state->getLogEvents(), |
118 | 124 | ]); |
119 | 125 | } |
120 | 126 | |
121 | - if ($this->state->getVariables() !== []) { |
|
127 | + if ($this->state->getVariables() !== []) |
|
128 | + { |
|
122 | 129 | $options['variables'] = $this->render('partials/variables', [ |
123 | 130 | 'variables' => $this->state->getVariables(), |
124 | 131 | ]); |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | array $parameters = [], |
38 | 38 | string $header = '', |
39 | 39 | string $footer = '' |
40 | - ) { |
|
40 | + ){ |
|
41 | 41 | $this->function = $function; |
42 | 42 | $this->parameters = $parameters; |
43 | 43 | |
@@ -50,18 +50,18 @@ discard block |
||
50 | 50 | public function execute(ContainerInterface $container, OutputInterface $output): void |
51 | 51 | { |
52 | 52 | $function = $this->function; |
53 | - if (is_string($function) && strpos($function, ':') !== false) { |
|
53 | + if (is_string($function) && strpos($function, ':') !== false){ |
|
54 | 54 | $function = explode(':', str_replace('::', ':', $function)); |
55 | 55 | } |
56 | 56 | |
57 | - if (is_array($function) && isset($function[0]) && !is_object($function[0])) { |
|
57 | + if (is_array($function) && isset($function[0]) && !is_object($function[0])){ |
|
58 | 58 | $function[0] = $container->get($function[0]); |
59 | 59 | } |
60 | 60 | |
61 | 61 | /** @var ResolverInterface $resolver */ |
62 | 62 | $resolver = $container->get(ResolverInterface::class); |
63 | 63 | |
64 | - if (is_array($function)) { |
|
64 | + if (is_array($function)){ |
|
65 | 65 | $reflection = new \ReflectionMethod($function[0], $function[1]); |
66 | 66 | $reflection->invokeArgs($function[0], $resolver->resolveArguments($reflection, [ |
67 | 67 | 'output' => $output, |
@@ -50,18 +50,21 @@ |
||
50 | 50 | public function execute(ContainerInterface $container, OutputInterface $output): void |
51 | 51 | { |
52 | 52 | $function = $this->function; |
53 | - if (is_string($function) && strpos($function, ':') !== false) { |
|
53 | + if (is_string($function) && strpos($function, ':') !== false) |
|
54 | + { |
|
54 | 55 | $function = explode(':', str_replace('::', ':', $function)); |
55 | 56 | } |
56 | 57 | |
57 | - if (is_array($function) && isset($function[0]) && !is_object($function[0])) { |
|
58 | + if (is_array($function) && isset($function[0]) && !is_object($function[0])) |
|
59 | + { |
|
58 | 60 | $function[0] = $container->get($function[0]); |
59 | 61 | } |
60 | 62 | |
61 | 63 | /** @var ResolverInterface $resolver */ |
62 | 64 | $resolver = $container->get(ResolverInterface::class); |
63 | 65 | |
64 | - if (is_array($function)) { |
|
66 | + if (is_array($function)) |
|
67 | + { |
|
65 | 68 | $reflection = new \ReflectionMethod($function[0], $function[1]); |
66 | 69 | $reflection->invokeArgs($function[0], $resolver->resolveArguments($reflection, [ |
67 | 70 | 'output' => $output, |
@@ -103,7 +103,8 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function handle(Request $request): Response |
105 | 105 | { |
106 | - if ($this->controller === null) { |
|
106 | + if ($this->controller === null) |
|
107 | + { |
|
107 | 108 | throw new HandlerException('Controller and action pair is not set'); |
108 | 109 | } |
109 | 110 | |
@@ -113,14 +114,16 @@ discard block |
||
113 | 114 | $output = $result = null; |
114 | 115 | |
115 | 116 | $response = $this->responseFactory->createResponse(200); |
116 | - try { |
|
117 | + try |
|
118 | + { |
|
117 | 119 | // run the core withing PSR-7 Request/Response scope |
118 | 120 | $result = $this->scope->runScope( |
119 | 121 | [ |
120 | 122 | Request::class => $request, |
121 | 123 | Response::class => $response, |
122 | 124 | ], |
123 | - function () use ($request) { |
|
125 | + function () use ($request) |
|
126 | + { |
|
124 | 127 | return $this->core->callAction( |
125 | 128 | $this->controller, |
126 | 129 | $this->getAction($request), |
@@ -128,14 +131,21 @@ discard block |
||
128 | 131 | ); |
129 | 132 | } |
130 | 133 | ); |
131 | - } catch (ControllerException $e) { |
|
134 | + } |
|
135 | + catch (ControllerException $e) |
|
136 | + { |
|
132 | 137 | ob_get_clean(); |
133 | 138 | throw $this->mapException($e); |
134 | - } catch (\Throwable $e) { |
|
139 | + } |
|
140 | + catch (\Throwable $e) |
|
141 | + { |
|
135 | 142 | ob_get_clean(); |
136 | 143 | throw $e; |
137 | - } finally { |
|
138 | - while (ob_get_level() > $outputLevel + 1) { |
|
144 | + } |
|
145 | + finally |
|
146 | + { |
|
147 | + while (ob_get_level() > $outputLevel + 1) |
|
148 | + { |
|
139 | 149 | $output = ob_get_clean() . $output; |
140 | 150 | } |
141 | 151 | } |
@@ -153,7 +163,8 @@ discard block |
||
153 | 163 | */ |
154 | 164 | private function getAction(Request $request): string |
155 | 165 | { |
156 | - if ($this->verbActions) { |
|
166 | + if ($this->verbActions) |
|
167 | + { |
|
157 | 168 | return strtolower($request->getMethod()) . ucfirst($this->action); |
158 | 169 | } |
159 | 170 | |
@@ -170,17 +181,22 @@ discard block |
||
170 | 181 | */ |
171 | 182 | private function wrapResponse(Response $response, $result = null, string $output = ''): Response |
172 | 183 | { |
173 | - if ($result instanceof Response) { |
|
174 | - if ($output !== '' && $result->getBody()->isWritable()) { |
|
184 | + if ($result instanceof Response) |
|
185 | + { |
|
186 | + if ($output !== '' && $result->getBody()->isWritable()) |
|
187 | + { |
|
175 | 188 | $result->getBody()->write($output); |
176 | 189 | } |
177 | 190 | |
178 | 191 | return $result; |
179 | 192 | } |
180 | 193 | |
181 | - if (is_array($result) || $result instanceof \JsonSerializable) { |
|
194 | + if (is_array($result) || $result instanceof \JsonSerializable) |
|
195 | + { |
|
182 | 196 | $response = $this->writeJson($response, $result); |
183 | - } else { |
|
197 | + } |
|
198 | + else |
|
199 | + { |
|
184 | 200 | $response->getBody()->write((string)$result); |
185 | 201 | } |
186 | 202 | |
@@ -198,7 +214,8 @@ discard block |
||
198 | 214 | */ |
199 | 215 | private function mapException(ControllerException $exception): ClientException |
200 | 216 | { |
201 | - switch ($exception->getCode()) { |
|
217 | + switch ($exception->getCode()) |
|
218 | + { |
|
202 | 219 | case ControllerException::BAD_ACTION: |
203 | 220 | case ControllerException::NOT_FOUND: |
204 | 221 | return new NotFoundException($exception->getMessage()); |
@@ -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 => $values) { |
|
204 | - if (empty($parameters[$key])) { |
|
203 | + foreach ($this->constrains as $key => $values){ |
|
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); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function __construct(LoggerInterface $logger = null) |
60 | 60 | { |
61 | - if (!empty($logger)) { |
|
61 | + if (!empty($logger)){ |
|
62 | 62 | $this->setLogger($logger); |
63 | 63 | } |
64 | 64 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $r = $this->getRenderer($target); |
87 | 87 | $dump = $r->wrapContent($this->renderValue($r, $value)); |
88 | 88 | |
89 | - switch ($target) { |
|
89 | + switch ($target){ |
|
90 | 90 | case self::OUTPUT: |
91 | 91 | echo $dump; |
92 | 92 | break; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | return $dump; |
96 | 96 | |
97 | 97 | case self::LOGGER: |
98 | - if ($this->logger == null) { |
|
98 | + if ($this->logger == null){ |
|
99 | 99 | throw new DumperException('Unable to dump value to log, no associated LoggerInterface'); |
100 | 100 | } |
101 | 101 | $this->logger->debug($dump); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function setRenderer(int $target, RendererInterface $renderer): Dumper |
121 | 121 | { |
122 | - if (!isset($this->targets[$target])) { |
|
122 | + if (!isset($this->targets[$target])){ |
|
123 | 123 | throw new DumperException(sprintf('Undefined dump target %d', $target)); |
124 | 124 | } |
125 | 125 | |
@@ -138,19 +138,19 @@ discard block |
||
138 | 138 | */ |
139 | 139 | private function getRenderer(int $target): RendererInterface |
140 | 140 | { |
141 | - if ($target == self::OUTPUT && System::isCLI()) { |
|
142 | - if (System::isColorsSupported(STDOUT)) { |
|
141 | + if ($target == self::OUTPUT && System::isCLI()){ |
|
142 | + if (System::isColorsSupported(STDOUT)){ |
|
143 | 143 | $target = self::OUTPUT_CLI_COLORS; |
144 | - } else { |
|
144 | + }else{ |
|
145 | 145 | $target = self::OUTPUT_CLI; |
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | - if (!isset($this->targets[$target])) { |
|
149 | + if (!isset($this->targets[$target])){ |
|
150 | 150 | throw new DumperException(sprintf('Undefined dump target %d', $target)); |
151 | 151 | } |
152 | 152 | |
153 | - if (is_string($this->targets[$target])) { |
|
153 | + if (is_string($this->targets[$target])){ |
|
154 | 154 | $this->targets[$target] = new $this->targets[$target](); |
155 | 155 | } |
156 | 156 | |
@@ -175,32 +175,32 @@ discard block |
||
175 | 175 | int $level = 0, |
176 | 176 | bool $hideHeader = false |
177 | 177 | ): string { |
178 | - if (!$hideHeader && !empty($name)) { |
|
179 | - $header = $r->indent($level) . $r->apply($name, 'name') . $r->apply(' = ', 'syntax', '='); |
|
180 | - } else { |
|
178 | + if (!$hideHeader && !empty($name)){ |
|
179 | + $header = $r->indent($level).$r->apply($name, 'name').$r->apply(' = ', 'syntax', '='); |
|
180 | + }else{ |
|
181 | 181 | $header = $r->indent($level); |
182 | 182 | } |
183 | 183 | |
184 | - if ($level > $this->maxLevel) { |
|
184 | + if ($level > $this->maxLevel){ |
|
185 | 185 | //Renderer is not reference based, we can't dump too deep values |
186 | - return $r->indent($level) . $r->apply('-too deep-', 'maxLevel') . "\n"; |
|
186 | + return $r->indent($level).$r->apply('-too deep-', 'maxLevel')."\n"; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | $type = strtolower(gettype($value)); |
190 | 190 | |
191 | - if ($type == 'array') { |
|
192 | - return $header . $this->renderArray($r, $value, $level, $hideHeader); |
|
191 | + if ($type == 'array'){ |
|
192 | + return $header.$this->renderArray($r, $value, $level, $hideHeader); |
|
193 | 193 | } |
194 | 194 | |
195 | - if ($type == 'object') { |
|
196 | - return $header . $this->renderObject($r, $value, $level, $hideHeader); |
|
195 | + if ($type == 'object'){ |
|
196 | + return $header.$this->renderObject($r, $value, $level, $hideHeader); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ($type == 'resource') { |
|
199 | + if ($type == 'resource'){ |
|
200 | 200 | //No need to dump resource value |
201 | - $element = get_resource_type($value) . ' resource '; |
|
201 | + $element = get_resource_type($value).' resource '; |
|
202 | 202 | |
203 | - return $header . $r->apply($element, 'type', 'resource') . "\n"; |
|
203 | + return $header.$r->apply($element, 'type', 'resource')."\n"; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | //Value length |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $header .= $r->apply("{$type}({$length})", 'type', $type); |
211 | 211 | |
212 | 212 | $element = null; |
213 | - switch ($type) { |
|
213 | + switch ($type){ |
|
214 | 214 | case 'string': |
215 | 215 | $element = $r->escapeStrings() ? htmlspecialchars($value) : $value; |
216 | 216 | break; |
@@ -220,14 +220,14 @@ discard block |
||
220 | 220 | break; |
221 | 221 | |
222 | 222 | default: |
223 | - if ($value !== null) { |
|
223 | + if ($value !== null){ |
|
224 | 224 | //Not showing null value, type is enough |
225 | 225 | $element = var_export($value, true); |
226 | 226 | } |
227 | 227 | } |
228 | 228 | |
229 | 229 | //Including value |
230 | - return $header . ' ' . $r->apply($element, 'value', $type) . "\n"; |
|
230 | + return $header.' '.$r->apply($element, 'value', $type)."\n"; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -240,19 +240,19 @@ discard block |
||
240 | 240 | */ |
241 | 241 | private function renderArray(RendererInterface $r, array $array, int $level, bool $hideHeader = false): string |
242 | 242 | { |
243 | - if (!$hideHeader) { |
|
243 | + if (!$hideHeader){ |
|
244 | 244 | $count = count($array); |
245 | 245 | |
246 | 246 | //Array size and scope |
247 | - $output = $r->apply("array({$count})", 'type', 'array') . "\n"; |
|
248 | - $output .= $r->indent($level) . $r->apply('[', 'syntax', '[') . "\n"; |
|
249 | - } else { |
|
247 | + $output = $r->apply("array({$count})", 'type', 'array')."\n"; |
|
248 | + $output .= $r->indent($level).$r->apply('[', 'syntax', '[')."\n"; |
|
249 | + }else{ |
|
250 | 250 | $output = ''; |
251 | 251 | } |
252 | 252 | |
253 | - foreach ($array as $key => $value) { |
|
254 | - if (!is_numeric($key)) { |
|
255 | - if (is_string($key) && $r->escapeStrings()) { |
|
253 | + foreach ($array as $key => $value){ |
|
254 | + if (!is_numeric($key)){ |
|
255 | + if (is_string($key) && $r->escapeStrings()){ |
|
256 | 256 | $key = htmlspecialchars($key); |
257 | 257 | } |
258 | 258 | |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | $output .= $this->renderValue($r, $value, "[{$key}]", $level + 1); |
263 | 263 | } |
264 | 264 | |
265 | - if (!$hideHeader) { |
|
265 | + if (!$hideHeader){ |
|
266 | 266 | //Closing array scope |
267 | - $output .= $r->indent($level) . $r->apply(']', 'syntax', ']') . "\n"; |
|
267 | + $output .= $r->indent($level).$r->apply(']', 'syntax', ']')."\n"; |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | return $output; |
@@ -286,47 +286,47 @@ discard block |
||
286 | 286 | bool $hideHeader = false, |
287 | 287 | string $class = '' |
288 | 288 | ): string { |
289 | - if (!$hideHeader) { |
|
290 | - $type = ($class ?: get_class($value)) . ' object '; |
|
289 | + if (!$hideHeader){ |
|
290 | + $type = ($class ?: get_class($value)).' object '; |
|
291 | 291 | |
292 | - $header = $r->apply($type, 'type', 'object') . "\n"; |
|
293 | - $header .= $r->indent($level) . $r->apply('(', 'syntax', '(') . "\n"; |
|
294 | - } else { |
|
292 | + $header = $r->apply($type, 'type', 'object')."\n"; |
|
293 | + $header .= $r->indent($level).$r->apply('(', 'syntax', '(')."\n"; |
|
294 | + }else{ |
|
295 | 295 | $header = ''; |
296 | 296 | } |
297 | 297 | |
298 | 298 | //Let's use method specifically created for dumping |
299 | - if (method_exists($value, '__debugInfo') || $value instanceof \Closure) { |
|
300 | - if ($value instanceof \Closure) { |
|
299 | + if (method_exists($value, '__debugInfo') || $value instanceof \Closure){ |
|
300 | + if ($value instanceof \Closure){ |
|
301 | 301 | $debugInfo = $this->describeClosure($value); |
302 | - } else { |
|
302 | + }else{ |
|
303 | 303 | $debugInfo = $value->__debugInfo(); |
304 | 304 | } |
305 | 305 | |
306 | - if (is_array($debugInfo)) { |
|
306 | + if (is_array($debugInfo)){ |
|
307 | 307 | //Pretty view |
308 | 308 | $debugInfo = (object)$debugInfo; |
309 | 309 | } |
310 | 310 | |
311 | - if (is_object($debugInfo)) { |
|
311 | + if (is_object($debugInfo)){ |
|
312 | 312 | //We are not including syntax elements here |
313 | 313 | return $this->renderObject($r, $debugInfo, $level, false, get_class($value)); |
314 | 314 | } |
315 | 315 | |
316 | 316 | return $header |
317 | 317 | . $this->renderValue($r, $debugInfo, '', $level + (is_scalar($value)), true) |
318 | - . $r->indent($level) . $r->apply(')', 'syntax', ')') . "\n"; |
|
318 | + . $r->indent($level).$r->apply(')', 'syntax', ')')."\n"; |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | $refection = new \ReflectionObject($value); |
322 | 322 | |
323 | 323 | $output = ''; |
324 | - foreach ($refection->getProperties() as $property) { |
|
324 | + foreach ($refection->getProperties() as $property){ |
|
325 | 325 | $output .= $this->renderProperty($r, $value, $property, $level); |
326 | 326 | } |
327 | 327 | |
328 | 328 | //Header, content, footer |
329 | - return $header . $output . $r->indent($level) . $r->apply(')', 'syntax', ')') . "\n"; |
|
329 | + return $header.$output.$r->indent($level).$r->apply(')', 'syntax', ')')."\n"; |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | */ |
340 | 340 | private function renderProperty(RendererInterface $r, $value, \ReflectionProperty $p, int $level): string |
341 | 341 | { |
342 | - if ($p->isStatic()) { |
|
342 | + if ($p->isStatic()){ |
|
343 | 343 | return ''; |
344 | 344 | } |
345 | 345 | |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | !($value instanceof \stdClass) |
348 | 348 | && is_string($p->getDocComment()) |
349 | 349 | && strpos($p->getDocComment(), '@internal') !== false |
350 | - ) { |
|
350 | + ){ |
|
351 | 351 | // Memory loop while reading doc comment for stdClass variables? |
352 | 352 | // Report a PHP bug about treating comment INSIDE property declaration as doc comment. |
353 | 353 | return ''; |
@@ -359,11 +359,11 @@ discard block |
||
359 | 359 | //To read private and protected properties |
360 | 360 | $p->setAccessible(true); |
361 | 361 | |
362 | - if ($value instanceof \stdClass) { |
|
362 | + if ($value instanceof \stdClass){ |
|
363 | 363 | $name = $r->apply($p->getName(), 'dynamic'); |
364 | - } else { |
|
364 | + }else{ |
|
365 | 365 | //Property name includes access level |
366 | - $name = $p->getName() . $r->apply(':' . $access, 'access', $access); |
|
366 | + $name = $p->getName().$r->apply(':'.$access, 'access', $access); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | return $this->renderValue($r, $p->getValue($value), $name, $level + 1); |
@@ -377,14 +377,14 @@ discard block |
||
377 | 377 | */ |
378 | 378 | private function describeClosure(\Closure $closure): array |
379 | 379 | { |
380 | - try { |
|
380 | + try{ |
|
381 | 381 | $r = new \ReflectionFunction($closure); |
382 | - } catch (\ReflectionException $e) { |
|
382 | + }catch (\ReflectionException $e){ |
|
383 | 383 | return ['closure' => 'unable to resolve']; |
384 | 384 | } |
385 | 385 | |
386 | 386 | return [ |
387 | - 'name' => $r->getName() . " (lines {$r->getStartLine()}:{$r->getEndLine()})", |
|
387 | + 'name' => $r->getName()." (lines {$r->getStartLine()}:{$r->getEndLine()})", |
|
388 | 388 | 'file' => $r->getFileName(), |
389 | 389 | 'this' => $r->getClosureThis(), |
390 | 390 | ]; |
@@ -399,9 +399,9 @@ discard block |
||
399 | 399 | */ |
400 | 400 | private function getAccess(\ReflectionProperty $p): string |
401 | 401 | { |
402 | - if ($p->isPrivate()) { |
|
402 | + if ($p->isPrivate()){ |
|
403 | 403 | return 'private'; |
404 | - } elseif ($p->isProtected()) { |
|
404 | + } elseif ($p->isProtected()){ |
|
405 | 405 | return 'protected'; |
406 | 406 | } |
407 | 407 |