@@ -26,5 +26,5 @@ |
||
26 | 26 | * @param MessagesList $messages |
27 | 27 | * @throws BroadcastException |
28 | 28 | */ |
29 | - public function publish(iterable|string|\Stringable $topics, iterable|string $messages): void; |
|
29 | + public function publish(iterable | string | \Stringable $topics, iterable | string $messages): void; |
|
30 | 30 | } |
@@ -22,20 +22,20 @@ discard block |
||
22 | 22 | private readonly ResponseFactoryInterface $responseFactory, |
23 | 23 | private readonly ?string $authorizationPath = null, |
24 | 24 | private readonly ?EventDispatcherInterface $dispatcher = null |
25 | - ) { |
|
25 | + ){ |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | public function process( |
29 | 29 | ServerRequestInterface $request, |
30 | 30 | RequestHandlerInterface $handler |
31 | 31 | ): ResponseInterface { |
32 | - if ($request->getUri()->getPath() !== $this->authorizationPath) { |
|
32 | + if ($request->getUri()->getPath() !== $this->authorizationPath){ |
|
33 | 33 | return $handler->handle($request); |
34 | 34 | } |
35 | 35 | |
36 | - if ($this->broadcast instanceof GuardInterface) { |
|
36 | + if ($this->broadcast instanceof GuardInterface){ |
|
37 | 37 | $status = $this->broadcast->authorize($request); |
38 | - } else { |
|
38 | + }else{ |
|
39 | 39 | $status = new AuthorizationStatus( |
40 | 40 | success: true, |
41 | 41 | topics: null |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | |
45 | 45 | $this->dispatcher?->dispatch(new Authorized($status, $request)); |
46 | 46 | |
47 | - if ($status->response !== null) { |
|
47 | + if ($status->response !== null){ |
|
48 | 48 | return $status->response; |
49 | 49 | } |
50 | 50 | |
51 | - if (!$status->success) { |
|
51 | + if (!$status->success){ |
|
52 | 52 | return $this->responseFactory->createResponse(403); |
53 | 53 | } |
54 | 54 |
@@ -29,13 +29,17 @@ discard block |
||
29 | 29 | ServerRequestInterface $request, |
30 | 30 | RequestHandlerInterface $handler |
31 | 31 | ): ResponseInterface { |
32 | - if ($request->getUri()->getPath() !== $this->authorizationPath) { |
|
32 | + if ($request->getUri()->getPath() !== $this->authorizationPath) |
|
33 | + { |
|
33 | 34 | return $handler->handle($request); |
34 | 35 | } |
35 | 36 | |
36 | - if ($this->broadcast instanceof GuardInterface) { |
|
37 | + if ($this->broadcast instanceof GuardInterface) |
|
38 | + { |
|
37 | 39 | $status = $this->broadcast->authorize($request); |
38 | - } else { |
|
40 | + } |
|
41 | + else |
|
42 | + { |
|
39 | 43 | $status = new AuthorizationStatus( |
40 | 44 | success: true, |
41 | 45 | topics: null |
@@ -44,11 +48,13 @@ discard block |
||
44 | 48 | |
45 | 49 | $this->dispatcher?->dispatch(new Authorized($status, $request)); |
46 | 50 | |
47 | - if ($status->response !== null) { |
|
51 | + if ($status->response !== null) |
|
52 | + { |
|
48 | 53 | return $status->response; |
49 | 54 | } |
50 | 55 | |
51 | - if (!$status->success) { |
|
56 | + if (!$status->success) |
|
57 | + { |
|
52 | 58 | return $this->responseFactory->createResponse(403); |
53 | 59 | } |
54 | 60 |
@@ -13,10 +13,10 @@ |
||
13 | 13 | */ |
14 | 14 | public function __construct( |
15 | 15 | public readonly bool $success, |
16 | - public readonly ?array $topics, |
|
16 | + public readonly ? array $topics, |
|
17 | 17 | public readonly array $attributes = [], |
18 | 18 | public readonly ?ResponseInterface $response = null |
19 | - ) { |
|
19 | + ){ |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -26,7 +26,7 @@ |
||
26 | 26 | public function get(array $values): array |
27 | 27 | { |
28 | 28 | $output = []; |
29 | - foreach ($values as $key => $value) { |
|
29 | + foreach ($values as $key => $value){ |
|
30 | 30 | $output[$key] = self::TYPE_DEFAULTS[\gettype($value)] ?? null; |
31 | 31 | } |
32 | 32 |
@@ -26,7 +26,8 @@ |
||
26 | 26 | public function get(array $values): array |
27 | 27 | { |
28 | 28 | $output = []; |
29 | - foreach ($values as $key => $value) { |
|
29 | + foreach ($values as $key => $value) |
|
30 | + { |
|
30 | 31 | $output[$key] = self::TYPE_DEFAULTS[\gettype($value)] ?? null; |
31 | 32 | } |
32 | 33 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | public function getAnnotation(mixed $value): string |
28 | 28 | { |
29 | - if (\is_array($value)) { |
|
29 | + if (\is_array($value)){ |
|
30 | 30 | return $this->arrayAnnotationString($value); |
31 | 31 | } |
32 | 32 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | private function arrayAnnotationString(array $value): string |
42 | 42 | { |
43 | 43 | $types = []; |
44 | - foreach ($value as $item) { |
|
44 | + foreach ($value as $item){ |
|
45 | 45 | $types[] = \gettype($item); |
46 | 46 | } |
47 | 47 | $types = \array_unique($types); |
@@ -26,7 +26,8 @@ discard block |
||
26 | 26 | |
27 | 27 | public function getAnnotation(mixed $value): string |
28 | 28 | { |
29 | - if (\is_array($value)) { |
|
29 | + if (\is_array($value)) |
|
30 | + { |
|
30 | 31 | return $this->arrayAnnotationString($value); |
31 | 32 | } |
32 | 33 | |
@@ -41,7 +42,8 @@ discard block |
||
41 | 42 | private function arrayAnnotationString(array $value): string |
42 | 43 | { |
43 | 44 | $types = []; |
44 | - foreach ($value as $item) { |
|
45 | + foreach ($value as $item) |
|
46 | + { |
|
45 | 47 | $types[] = \gettype($item); |
46 | 48 | } |
47 | 49 | $types = \array_unique($types); |
@@ -24,8 +24,8 @@ discard block |
||
24 | 24 | public function getDirectives(): array |
25 | 25 | { |
26 | 26 | $directives = []; |
27 | - foreach ($this->config['directives'] as $directive) { |
|
28 | - if (\is_object($directive) && !$directive instanceof Autowire) { |
|
27 | + foreach ($this->config['directives'] as $directive){ |
|
28 | + if (\is_object($directive) && !$directive instanceof Autowire){ |
|
29 | 29 | $directives[] = $directive; |
30 | 30 | continue; |
31 | 31 | } |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | public function getProcessors(): array |
43 | 43 | { |
44 | 44 | $processors = []; |
45 | - foreach ($this->config['processors'] as $processor) { |
|
46 | - if (is_object($processor) && !$processor instanceof Autowire) { |
|
45 | + foreach ($this->config['processors'] as $processor){ |
|
46 | + if (is_object($processor) && !$processor instanceof Autowire){ |
|
47 | 47 | $processors[] = $processor; |
48 | 48 | continue; |
49 | 49 | } |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | public function getVisitors(int $stage): array |
58 | 58 | { |
59 | 59 | $visitors = []; |
60 | - foreach ($this->config['visitors'][$stage] ?? [] as $visitor) { |
|
61 | - if (\is_object($visitor) && !$visitor instanceof Autowire) { |
|
60 | + foreach ($this->config['visitors'][$stage] ?? [] as $visitor){ |
|
61 | + if (\is_object($visitor) && !$visitor instanceof Autowire){ |
|
62 | 62 | $visitors[] = $visitor; |
63 | 63 | continue; |
64 | 64 | } |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | */ |
75 | 75 | private function wire(mixed $item): Autowire |
76 | 76 | { |
77 | - if ($item instanceof Autowire) { |
|
77 | + if ($item instanceof Autowire){ |
|
78 | 78 | return $item; |
79 | 79 | } |
80 | 80 | |
81 | - if (\is_string($item)) { |
|
81 | + if (\is_string($item)){ |
|
82 | 82 | return new Autowire($item); |
83 | 83 | } |
84 | 84 |
@@ -24,8 +24,10 @@ discard block |
||
24 | 24 | public function getDirectives(): array |
25 | 25 | { |
26 | 26 | $directives = []; |
27 | - foreach ($this->config['directives'] as $directive) { |
|
28 | - if (\is_object($directive) && !$directive instanceof Autowire) { |
|
27 | + foreach ($this->config['directives'] as $directive) |
|
28 | + { |
|
29 | + if (\is_object($directive) && !$directive instanceof Autowire) |
|
30 | + { |
|
29 | 31 | $directives[] = $directive; |
30 | 32 | continue; |
31 | 33 | } |
@@ -42,8 +44,10 @@ discard block |
||
42 | 44 | public function getProcessors(): array |
43 | 45 | { |
44 | 46 | $processors = []; |
45 | - foreach ($this->config['processors'] as $processor) { |
|
46 | - if (is_object($processor) && !$processor instanceof Autowire) { |
|
47 | + foreach ($this->config['processors'] as $processor) |
|
48 | + { |
|
49 | + if (is_object($processor) && !$processor instanceof Autowire) |
|
50 | + { |
|
47 | 51 | $processors[] = $processor; |
48 | 52 | continue; |
49 | 53 | } |
@@ -57,8 +61,10 @@ discard block |
||
57 | 61 | public function getVisitors(int $stage): array |
58 | 62 | { |
59 | 63 | $visitors = []; |
60 | - foreach ($this->config['visitors'][$stage] ?? [] as $visitor) { |
|
61 | - if (\is_object($visitor) && !$visitor instanceof Autowire) { |
|
64 | + foreach ($this->config['visitors'][$stage] ?? [] as $visitor) |
|
65 | + { |
|
66 | + if (\is_object($visitor) && !$visitor instanceof Autowire) |
|
67 | + { |
|
62 | 68 | $visitors[] = $visitor; |
63 | 69 | continue; |
64 | 70 | } |
@@ -74,11 +80,13 @@ discard block |
||
74 | 80 | */ |
75 | 81 | private function wire(mixed $item): Autowire |
76 | 82 | { |
77 | - if ($item instanceof Autowire) { |
|
83 | + if ($item instanceof Autowire) |
|
84 | + { |
|
78 | 85 | return $item; |
79 | 86 | } |
80 | 87 | |
81 | - if (\is_string($item)) { |
|
88 | + if (\is_string($item)) |
|
89 | + { |
|
82 | 90 | return new Autowire($item); |
83 | 91 | } |
84 | 92 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | { |
17 | 17 | public function __construct( |
18 | 18 | private readonly ContainerInterface $container |
19 | - ) { |
|
19 | + ){ |
|
20 | 20 | parent::__construct(); |
21 | 21 | } |
22 | 22 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function renderRoute(Directive $directive): string |
27 | 27 | { |
28 | - if (\count($directive->values) < 1) { |
|
28 | + if (\count($directive->values) < 1){ |
|
29 | 29 | throw new DirectiveException( |
30 | 30 | 'Unable to call @route directive, at least 1 value is required', |
31 | 31 | $directive->getContext() |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | { |
46 | 46 | $vars = []; |
47 | 47 | $restore = []; |
48 | - foreach ($params as $key => $value) { |
|
49 | - if (\is_string($value) && \preg_match('#\{.*\}#', $value)) { |
|
48 | + foreach ($params as $key => $value){ |
|
49 | + if (\is_string($value) && \preg_match('#\{.*\}#', $value)){ |
|
50 | 50 | $restore[\sprintf('__%s__', $key)] = $value; |
51 | 51 | $value = \sprintf('__%s__', $key); |
52 | 52 | } |
@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | $vars[$key] = $value; |
55 | 55 | } |
56 | 56 | |
57 | - try { |
|
57 | + try{ |
|
58 | 58 | return \strtr( |
59 | 59 | $this->container->get(RouterInterface::class)->uri($route, $vars)->__toString(), |
60 | 60 | $restore |
61 | 61 | ); |
62 | - } catch (UndefinedRouteException $e) { |
|
62 | + }catch (UndefinedRouteException $e){ |
|
63 | 63 | throw new RouterException("No such route {$route}", $e->getCode(), $e); |
64 | 64 | } |
65 | 65 | } |
@@ -25,7 +25,8 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function renderRoute(Directive $directive): string |
27 | 27 | { |
28 | - if (\count($directive->values) < 1) { |
|
28 | + if (\count($directive->values) < 1) |
|
29 | + { |
|
29 | 30 | throw new DirectiveException( |
30 | 31 | 'Unable to call @route directive, at least 1 value is required', |
31 | 32 | $directive->getContext() |
@@ -45,8 +46,10 @@ discard block |
||
45 | 46 | { |
46 | 47 | $vars = []; |
47 | 48 | $restore = []; |
48 | - foreach ($params as $key => $value) { |
|
49 | - if (\is_string($value) && \preg_match('#\{.*\}#', $value)) { |
|
49 | + foreach ($params as $key => $value) |
|
50 | + { |
|
51 | + if (\is_string($value) && \preg_match('#\{.*\}#', $value)) |
|
52 | + { |
|
50 | 53 | $restore[\sprintf('__%s__', $key)] = $value; |
51 | 54 | $value = \sprintf('__%s__', $key); |
52 | 55 | } |
@@ -54,12 +57,15 @@ discard block |
||
54 | 57 | $vars[$key] = $value; |
55 | 58 | } |
56 | 59 | |
57 | - try { |
|
60 | + try |
|
61 | + { |
|
58 | 62 | return \strtr( |
59 | 63 | $this->container->get(RouterInterface::class)->uri($route, $vars)->__toString(), |
60 | 64 | $restore |
61 | 65 | ); |
62 | - } catch (UndefinedRouteException $e) { |
|
66 | + } |
|
67 | + catch (UndefinedRouteException $e) |
|
68 | + { |
|
63 | 69 | throw new RouterException("No such route {$route}", $e->getCode(), $e); |
64 | 70 | } |
65 | 71 | } |
@@ -17,14 +17,16 @@ |
||
17 | 17 | */ |
18 | 18 | public function renderInject(Directive $directive): string |
19 | 19 | { |
20 | - if (\count($directive->values) < 2 || (string) $directive->values[0] === '') { |
|
20 | + if (\count($directive->values) < 2 || (string) $directive->values[0] === '') |
|
21 | + { |
|
21 | 22 | throw new DirectiveException( |
22 | 23 | 'Unable to call @inject directive, 2 values required', |
23 | 24 | $directive->getContext() |
24 | 25 | ); |
25 | 26 | } |
26 | 27 | |
27 | - if ($directive->values[0][0] === '$') { |
|
28 | + if ($directive->values[0][0] === '$') |
|
29 | + { |
|
28 | 30 | return \sprintf( |
29 | 31 | '<?php %s = $this->container->get(%s); ?>', |
30 | 32 | $directive->values[0], |
@@ -17,14 +17,14 @@ discard block |
||
17 | 17 | */ |
18 | 18 | public function renderInject(Directive $directive): string |
19 | 19 | { |
20 | - if (\count($directive->values) < 2 || (string) $directive->values[0] === '') { |
|
20 | + if (\count($directive->values) < 2 || (string)$directive->values[0] === ''){ |
|
21 | 21 | throw new DirectiveException( |
22 | 22 | 'Unable to call @inject directive, 2 values required', |
23 | 23 | $directive->getContext() |
24 | 24 | ); |
25 | 25 | } |
26 | 26 | |
27 | - if ($directive->values[0][0] === '$') { |
|
27 | + if ($directive->values[0][0] === '$'){ |
|
28 | 28 | return \sprintf( |
29 | 29 | '<?php %s = $this->container->get(%s); ?>', |
30 | 30 | $directive->values[0], |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | return \sprintf( |
36 | 36 | '<?php $%s = $this->container->get(%s); ?>', |
37 | - \trim((string) $directive->values[0], '\'"'), |
|
37 | + \trim((string)$directive->values[0], '\'"'), |
|
38 | 38 | $directive->values[1] |
39 | 39 | ); |
40 | 40 | } |
@@ -30,30 +30,30 @@ discard block |
||
30 | 30 | |
31 | 31 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
32 | 32 | { |
33 | - if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag) { |
|
33 | + if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag){ |
|
34 | 34 | return null; |
35 | 35 | } |
36 | 36 | |
37 | - if ($node instanceof Tag && \in_array($node->name, self::EXCLUDE)) { |
|
37 | + if ($node instanceof Tag && \in_array($node->name, self::EXCLUDE)){ |
|
38 | 38 | // raw nodes |
39 | 39 | return null; |
40 | 40 | } |
41 | 41 | |
42 | 42 | $level = $this->getLevel($ctx); |
43 | - if ($level === null) { |
|
43 | + if ($level === null){ |
|
44 | 44 | // not available in some contexts |
45 | 45 | return null; |
46 | 46 | } |
47 | 47 | |
48 | - foreach ($node->nodes as $i => $child) { |
|
49 | - if (!$child instanceof Raw) { |
|
48 | + foreach ($node->nodes as $i => $child){ |
|
49 | + if (!$child instanceof Raw){ |
|
50 | 50 | continue; |
51 | 51 | } |
52 | 52 | |
53 | 53 | $position = self::BETWEEN_TAGS; |
54 | - if (!isset($node->nodes[$i + 1])) { |
|
54 | + if (!isset($node->nodes[$i + 1])){ |
|
55 | 55 | $position = self::BEFORE_CLOSE; |
56 | - } elseif ($node->nodes[$i + 1] instanceof PHP) { |
|
56 | + } elseif ($node->nodes[$i + 1] instanceof PHP){ |
|
57 | 57 | $position = self::BEFORE_PHP; |
58 | 58 | } |
59 | 59 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | private function indentContent(string $content, int $level, int $position = self::BETWEEN_TAGS): string |
76 | 76 | { |
77 | - if (!\str_contains($content, "\n")) { |
|
77 | + if (!\str_contains($content, "\n")){ |
|
78 | 78 | // no need to do anything |
79 | 79 | return $content; |
80 | 80 | } |
@@ -82,40 +82,40 @@ discard block |
||
82 | 82 | // we have to apply special rules to the first and the last lines |
83 | 83 | $lines = \explode("\n", $content); |
84 | 84 | |
85 | - foreach ($lines as $i => $line) { |
|
86 | - if (\trim($line) === '' && $i !== 0) { |
|
85 | + foreach ($lines as $i => $line){ |
|
86 | + if (\trim($line) === '' && $i !== 0){ |
|
87 | 87 | unset($lines[$i]); |
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | 91 | $lines = \array_values($lines); |
92 | - if ($lines === []) { |
|
92 | + if ($lines === []){ |
|
93 | 93 | $lines[] = ''; |
94 | 94 | } |
95 | 95 | |
96 | 96 | $result = ''; |
97 | - foreach ($lines as $i => $line) { |
|
98 | - if (\trim($line) !== '') { |
|
97 | + foreach ($lines as $i => $line){ |
|
98 | + if (\trim($line) !== ''){ |
|
99 | 99 | $line = $i === 0 ? \rtrim($line) : \trim($line); |
100 | 100 | } |
101 | 101 | |
102 | - if ($i !== (\count($lines) - 1)) { |
|
103 | - $result .= $line . "\n" . \str_repeat(self::INDENT, $level); |
|
102 | + if ($i !== (\count($lines) - 1)){ |
|
103 | + $result .= $line."\n".\str_repeat(self::INDENT, $level); |
|
104 | 104 | continue; |
105 | 105 | } |
106 | 106 | |
107 | 107 | // working with last line |
108 | - if ($position === self::BEFORE_PHP) { |
|
109 | - $result .= $line . "\n"; |
|
108 | + if ($position === self::BEFORE_PHP){ |
|
109 | + $result .= $line."\n"; |
|
110 | 110 | break; |
111 | 111 | } |
112 | 112 | |
113 | - if ($position === self::BEFORE_CLOSE) { |
|
114 | - $result .= $line . "\n" . \str_repeat(self::INDENT, max($level - 1, 0)); |
|
113 | + if ($position === self::BEFORE_CLOSE){ |
|
114 | + $result .= $line."\n".\str_repeat(self::INDENT, max($level - 1, 0)); |
|
115 | 115 | break; |
116 | 116 | } |
117 | 117 | |
118 | - $result .= $line . "\n" . \str_repeat(self::INDENT, $level); |
|
118 | + $result .= $line."\n".\str_repeat(self::INDENT, $level); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | return $result; |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | private function getLevel(VisitorContext $ctx): ?int |
125 | 125 | { |
126 | 126 | $level = 0; |
127 | - foreach ($ctx->getScope() as $node) { |
|
128 | - if ($node instanceof Attr) { |
|
127 | + foreach ($ctx->getScope() as $node){ |
|
128 | + if ($node instanceof Attr){ |
|
129 | 129 | return null; |
130 | 130 | } |
131 | 131 | |
132 | - if ($node instanceof Block || $node instanceof Template) { |
|
132 | + if ($node instanceof Block || $node instanceof Template){ |
|
133 | 133 | continue; |
134 | 134 | } |
135 | 135 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | */ |
149 | 149 | private function normalizeEndings(string $string, bool $joinMultiple = true): string |
150 | 150 | { |
151 | - if (!$joinMultiple) { |
|
151 | + if (!$joinMultiple){ |
|
152 | 152 | return \str_replace("\r\n", "\n", $string); |
153 | 153 | } |
154 | 154 |
@@ -30,30 +30,38 @@ discard block |
||
30 | 30 | |
31 | 31 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
32 | 32 | { |
33 | - if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag) { |
|
33 | + if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag) |
|
34 | + { |
|
34 | 35 | return null; |
35 | 36 | } |
36 | 37 | |
37 | - if ($node instanceof Tag && \in_array($node->name, self::EXCLUDE)) { |
|
38 | + if ($node instanceof Tag && \in_array($node->name, self::EXCLUDE)) |
|
39 | + { |
|
38 | 40 | // raw nodes |
39 | 41 | return null; |
40 | 42 | } |
41 | 43 | |
42 | 44 | $level = $this->getLevel($ctx); |
43 | - if ($level === null) { |
|
45 | + if ($level === null) |
|
46 | + { |
|
44 | 47 | // not available in some contexts |
45 | 48 | return null; |
46 | 49 | } |
47 | 50 | |
48 | - foreach ($node->nodes as $i => $child) { |
|
49 | - if (!$child instanceof Raw) { |
|
51 | + foreach ($node->nodes as $i => $child) |
|
52 | + { |
|
53 | + if (!$child instanceof Raw) |
|
54 | + { |
|
50 | 55 | continue; |
51 | 56 | } |
52 | 57 | |
53 | 58 | $position = self::BETWEEN_TAGS; |
54 | - if (!isset($node->nodes[$i + 1])) { |
|
59 | + if (!isset($node->nodes[$i + 1])) |
|
60 | + { |
|
55 | 61 | $position = self::BEFORE_CLOSE; |
56 | - } elseif ($node->nodes[$i + 1] instanceof PHP) { |
|
62 | + } |
|
63 | + elseif ($node->nodes[$i + 1] instanceof PHP) |
|
64 | + { |
|
57 | 65 | $position = self::BEFORE_PHP; |
58 | 66 | } |
59 | 67 | |
@@ -74,7 +82,8 @@ discard block |
||
74 | 82 | |
75 | 83 | private function indentContent(string $content, int $level, int $position = self::BETWEEN_TAGS): string |
76 | 84 | { |
77 | - if (!\str_contains($content, "\n")) { |
|
85 | + if (!\str_contains($content, "\n")) |
|
86 | + { |
|
78 | 87 | // no need to do anything |
79 | 88 | return $content; |
80 | 89 | } |
@@ -82,35 +91,43 @@ discard block |
||
82 | 91 | // we have to apply special rules to the first and the last lines |
83 | 92 | $lines = \explode("\n", $content); |
84 | 93 | |
85 | - foreach ($lines as $i => $line) { |
|
86 | - if (\trim($line) === '' && $i !== 0) { |
|
94 | + foreach ($lines as $i => $line) |
|
95 | + { |
|
96 | + if (\trim($line) === '' && $i !== 0) |
|
97 | + { |
|
87 | 98 | unset($lines[$i]); |
88 | 99 | } |
89 | 100 | } |
90 | 101 | |
91 | 102 | $lines = \array_values($lines); |
92 | - if ($lines === []) { |
|
103 | + if ($lines === []) |
|
104 | + { |
|
93 | 105 | $lines[] = ''; |
94 | 106 | } |
95 | 107 | |
96 | 108 | $result = ''; |
97 | - foreach ($lines as $i => $line) { |
|
98 | - if (\trim($line) !== '') { |
|
109 | + foreach ($lines as $i => $line) |
|
110 | + { |
|
111 | + if (\trim($line) !== '') |
|
112 | + { |
|
99 | 113 | $line = $i === 0 ? \rtrim($line) : \trim($line); |
100 | 114 | } |
101 | 115 | |
102 | - if ($i !== (\count($lines) - 1)) { |
|
116 | + if ($i !== (\count($lines) - 1)) |
|
117 | + { |
|
103 | 118 | $result .= $line . "\n" . \str_repeat(self::INDENT, $level); |
104 | 119 | continue; |
105 | 120 | } |
106 | 121 | |
107 | 122 | // working with last line |
108 | - if ($position === self::BEFORE_PHP) { |
|
123 | + if ($position === self::BEFORE_PHP) |
|
124 | + { |
|
109 | 125 | $result .= $line . "\n"; |
110 | 126 | break; |
111 | 127 | } |
112 | 128 | |
113 | - if ($position === self::BEFORE_CLOSE) { |
|
129 | + if ($position === self::BEFORE_CLOSE) |
|
130 | + { |
|
114 | 131 | $result .= $line . "\n" . \str_repeat(self::INDENT, max($level - 1, 0)); |
115 | 132 | break; |
116 | 133 | } |
@@ -124,12 +141,15 @@ discard block |
||
124 | 141 | private function getLevel(VisitorContext $ctx): ?int |
125 | 142 | { |
126 | 143 | $level = 0; |
127 | - foreach ($ctx->getScope() as $node) { |
|
128 | - if ($node instanceof Attr) { |
|
144 | + foreach ($ctx->getScope() as $node) |
|
145 | + { |
|
146 | + if ($node instanceof Attr) |
|
147 | + { |
|
129 | 148 | return null; |
130 | 149 | } |
131 | 150 | |
132 | - if ($node instanceof Block || $node instanceof Template) { |
|
151 | + if ($node instanceof Block || $node instanceof Template) |
|
152 | + { |
|
133 | 153 | continue; |
134 | 154 | } |
135 | 155 | |
@@ -148,7 +168,8 @@ discard block |
||
148 | 168 | */ |
149 | 169 | private function normalizeEndings(string $string, bool $joinMultiple = true): string |
150 | 170 | { |
151 | - if (!$joinMultiple) { |
|
171 | + if (!$joinMultiple) |
|
172 | + { |
|
152 | 173 | return \str_replace("\r\n", "\n", $string); |
153 | 174 | } |
154 | 175 |