@@ -24,9 +24,11 @@ discard block |
||
24 | 24 | $lines = \explode("\n", \str_replace("\r\n", "\n", $this->highlight($source))); |
25 | 25 | |
26 | 26 | $result = ''; |
27 | - foreach ($lines as $number => $code) { |
|
27 | + foreach ($lines as $number => $code) |
|
28 | + { |
|
28 | 29 | $human = $number + 1; |
29 | - if (!empty($around) && ($human < $line - $around || $human >= $line + $around + 1)) { |
|
30 | + if (!empty($around) && ($human < $line - $around || $human >= $line + $around + 1)) |
|
31 | + { |
|
30 | 32 | //Not included in a range |
31 | 33 | continue; |
32 | 34 | } |
@@ -44,7 +46,8 @@ discard block |
||
44 | 46 | { |
45 | 47 | $result = ''; |
46 | 48 | $previous = []; |
47 | - foreach ($this->getTokens($source) as $token) { |
|
49 | + foreach ($this->getTokens($source) as $token) |
|
50 | + { |
|
48 | 51 | $result .= $this->renderer->token($token, $previous); |
49 | 52 | $previous = $token; |
50 | 53 | } |
@@ -60,12 +63,15 @@ discard block |
||
60 | 63 | $tokens = []; |
61 | 64 | $line = 0; |
62 | 65 | |
63 | - foreach (\token_get_all($source) as $token) { |
|
64 | - if (isset($token[2])) { |
|
66 | + foreach (\token_get_all($source) as $token) |
|
67 | + { |
|
68 | + if (isset($token[2])) |
|
69 | + { |
|
65 | 70 | $line = $token[2]; |
66 | 71 | } |
67 | 72 | |
68 | - if (!\is_array($token)) { |
|
73 | + if (!\is_array($token)) |
|
74 | + { |
|
69 | 75 | $token = [$token, $token, $line]; |
70 | 76 | } |
71 | 77 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | { |
14 | 14 | public function __construct( |
15 | 15 | private readonly StyleInterface $renderer |
16 | - ) { |
|
16 | + ){ |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | $lines = \explode("\n", \str_replace("\r\n", "\n", $this->highlight($source))); |
25 | 25 | |
26 | 26 | $result = ''; |
27 | - foreach ($lines as $number => $code) { |
|
27 | + foreach ($lines as $number => $code){ |
|
28 | 28 | $human = $number + 1; |
29 | - if (!empty($around) && ($human < $line - $around || $human >= $line + $around + 1)) { |
|
29 | + if (!empty($around) && ($human < $line - $around || $human >= $line + $around + 1)){ |
|
30 | 30 | //Not included in a range |
31 | 31 | continue; |
32 | 32 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | { |
45 | 45 | $result = ''; |
46 | 46 | $previous = []; |
47 | - foreach ($this->getTokens($source) as $token) { |
|
47 | + foreach ($this->getTokens($source) as $token){ |
|
48 | 48 | $result .= $this->renderer->token($token, $previous); |
49 | 49 | $previous = $token; |
50 | 50 | } |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | $tokens = []; |
61 | 61 | $line = 0; |
62 | 62 | |
63 | - foreach (\token_get_all($source) as $token) { |
|
64 | - if (isset($token[2])) { |
|
63 | + foreach (\token_get_all($source) as $token){ |
|
64 | + if (isset($token[2])){ |
|
65 | 65 | $line = $token[2]; |
66 | 66 | } |
67 | 67 | |
68 | - if (!\is_array($token)) { |
|
68 | + if (!\is_array($token)){ |
|
69 | 69 | $token = [$token, $token, $line]; |
70 | 70 | } |
71 | 71 |
@@ -30,24 +30,24 @@ |
||
30 | 30 | |
31 | 31 | private function renderTrace(array $trace, Verbosity $verbosity): \Generator |
32 | 32 | { |
33 | - foreach ($trace as $item) { |
|
33 | + foreach ($trace as $item){ |
|
34 | 34 | $result = []; |
35 | 35 | |
36 | - if (isset($item['class'])) { |
|
36 | + if (isset($item['class'])){ |
|
37 | 37 | $result['function'] = \sprintf( |
38 | 38 | '%s%s%s()', |
39 | 39 | $item['class'], |
40 | 40 | $item['type'], |
41 | 41 | $item['function'] |
42 | 42 | ); |
43 | - } else { |
|
43 | + }else{ |
|
44 | 44 | $result['function'] = \sprintf( |
45 | 45 | '%s()', |
46 | 46 | $item['function'] |
47 | 47 | ); |
48 | 48 | } |
49 | 49 | |
50 | - if ($verbosity->value >= Verbosity::VERBOSE->value && isset($item['file'])) { |
|
50 | + if ($verbosity->value >= Verbosity::VERBOSE->value && isset($item['file'])){ |
|
51 | 51 | $result['at'] = [ |
52 | 52 | 'file' => $item['file'] ?? null, |
53 | 53 | 'line' => $item['line'] ?? null, |
@@ -30,24 +30,29 @@ |
||
30 | 30 | |
31 | 31 | private function renderTrace(array $trace, Verbosity $verbosity): \Generator |
32 | 32 | { |
33 | - foreach ($trace as $item) { |
|
33 | + foreach ($trace as $item) |
|
34 | + { |
|
34 | 35 | $result = []; |
35 | 36 | |
36 | - if (isset($item['class'])) { |
|
37 | + if (isset($item['class'])) |
|
38 | + { |
|
37 | 39 | $result['function'] = \sprintf( |
38 | 40 | '%s%s%s()', |
39 | 41 | $item['class'], |
40 | 42 | $item['type'], |
41 | 43 | $item['function'] |
42 | 44 | ); |
43 | - } else { |
|
45 | + } |
|
46 | + else |
|
47 | + { |
|
44 | 48 | $result['function'] = \sprintf( |
45 | 49 | '%s()', |
46 | 50 | $item['function'] |
47 | 51 | ); |
48 | 52 | } |
49 | 53 | |
50 | - if ($verbosity->value >= Verbosity::VERBOSE->value && isset($item['file'])) { |
|
54 | + if ($verbosity->value >= Verbosity::VERBOSE->value && isset($item['file'])) |
|
55 | + { |
|
51 | 56 | $result['at'] = [ |
52 | 57 | 'file' => $item['file'] ?? null, |
53 | 58 | 'line' => $item['line'] ?? null, |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | protected function getStacktrace(\Throwable $e): array |
28 | 28 | { |
29 | 29 | $stacktrace = $e->getTrace(); |
30 | - if (empty($stacktrace)) { |
|
30 | + if (empty($stacktrace)){ |
|
31 | 31 | return []; |
32 | 32 | } |
33 | 33 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | 'line' => $e->getLine(), |
38 | 38 | ] + $stacktrace[0]; |
39 | 39 | |
40 | - if ($stacktrace[0] !== $header) { |
|
40 | + if ($stacktrace[0] !== $header){ |
|
41 | 41 | \array_unshift($stacktrace, $header); |
42 | 42 | } |
43 | 43 |
@@ -27,7 +27,8 @@ discard block |
||
27 | 27 | protected function getStacktrace(\Throwable $e): array |
28 | 28 | { |
29 | 29 | $stacktrace = $e->getTrace(); |
30 | - if (empty($stacktrace)) { |
|
30 | + if (empty($stacktrace)) |
|
31 | + { |
|
31 | 32 | return []; |
32 | 33 | } |
33 | 34 | |
@@ -37,7 +38,8 @@ discard block |
||
37 | 38 | 'line' => $e->getLine(), |
38 | 39 | ] + $stacktrace[0]; |
39 | 40 | |
40 | - if ($stacktrace[0] !== $header) { |
|
41 | + if ($stacktrace[0] !== $header) |
|
42 | + { |
|
41 | 43 | \array_unshift($stacktrace, $header); |
42 | 44 | } |
43 | 45 |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | class ConsoleStyle implements StyleInterface |
14 | 14 | { |
15 | 15 | protected array $templates = [ |
16 | - 'token' => '%s%s' . Color::RESET, |
|
17 | - 'line' => Color::LIGHT_CYAN . ' %s ' . Color::RESET . " %s\n", |
|
18 | - 'active' => Color::BG_RED . ' ' . Color::LIGHT_WHITE . '%s ' . Color::RESET . " %s\n", |
|
16 | + 'token' => '%s%s'.Color::RESET, |
|
17 | + 'line' => Color::LIGHT_CYAN.' %s '.Color::RESET." %s\n", |
|
18 | + 'active' => Color::BG_RED.' '.Color::LIGHT_WHITE.'%s '.Color::RESET." %s\n", |
|
19 | 19 | ]; |
20 | 20 | |
21 | 21 | protected array $style = [ |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | T_VARIABLE, |
79 | 79 | ], |
80 | 80 | Color::LIGHT_YELLOW => [ |
81 | - '->' . T_STRING, |
|
82 | - '::' . T_STRING, |
|
81 | + '->'.T_STRING, |
|
82 | + '::'.T_STRING, |
|
83 | 83 | ], |
84 | 84 | ]; |
85 | 85 | |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | { |
88 | 88 | $style = $this->getStyle($token, $previous); |
89 | 89 | |
90 | - if (!\str_contains((string) $token[1], "\n")) { |
|
90 | + if (!\str_contains((string)$token[1], "\n")){ |
|
91 | 91 | return \sprintf($this->templates['token'], $style, $token[1]); |
92 | 92 | } |
93 | 93 | |
94 | 94 | $lines = []; |
95 | - foreach (\explode("\n", (string) $token[1]) as $line) { |
|
95 | + foreach (\explode("\n", (string)$token[1]) as $line){ |
|
96 | 96 | $lines[] = \sprintf($this->templates['token'], $style, $line); |
97 | 97 | } |
98 | 98 | |
@@ -113,16 +113,16 @@ discard block |
||
113 | 113 | */ |
114 | 114 | private function getStyle(array $token, array $previous): string |
115 | 115 | { |
116 | - if (!empty($previous)) { |
|
117 | - foreach ($this->style as $style => $tokens) { |
|
118 | - if (\in_array($previous[1] . $token[0], $tokens)) { |
|
116 | + if (!empty($previous)){ |
|
117 | + foreach ($this->style as $style => $tokens){ |
|
118 | + if (\in_array($previous[1].$token[0], $tokens)){ |
|
119 | 119 | return $style; |
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - foreach ($this->style as $style => $tokens) { |
|
125 | - if (\in_array($token[0], $tokens)) { |
|
124 | + foreach ($this->style as $style => $tokens){ |
|
125 | + if (\in_array($token[0], $tokens)){ |
|
126 | 126 | return $style; |
127 | 127 | } |
128 | 128 | } |
@@ -87,12 +87,14 @@ discard block |
||
87 | 87 | { |
88 | 88 | $style = $this->getStyle($token, $previous); |
89 | 89 | |
90 | - if (!\str_contains((string) $token[1], "\n")) { |
|
90 | + if (!\str_contains((string) $token[1], "\n")) |
|
91 | + { |
|
91 | 92 | return \sprintf($this->templates['token'], $style, $token[1]); |
92 | 93 | } |
93 | 94 | |
94 | 95 | $lines = []; |
95 | - foreach (\explode("\n", (string) $token[1]) as $line) { |
|
96 | + foreach (\explode("\n", (string) $token[1]) as $line) |
|
97 | + { |
|
96 | 98 | $lines[] = \sprintf($this->templates['token'], $style, $line); |
97 | 99 | } |
98 | 100 | |
@@ -113,16 +115,21 @@ discard block |
||
113 | 115 | */ |
114 | 116 | private function getStyle(array $token, array $previous): string |
115 | 117 | { |
116 | - if (!empty($previous)) { |
|
117 | - foreach ($this->style as $style => $tokens) { |
|
118 | - if (\in_array($previous[1] . $token[0], $tokens)) { |
|
118 | + if (!empty($previous)) |
|
119 | + { |
|
120 | + foreach ($this->style as $style => $tokens) |
|
121 | + { |
|
122 | + if (\in_array($previous[1] . $token[0], $tokens)) |
|
123 | + { |
|
119 | 124 | return $style; |
120 | 125 | } |
121 | 126 | } |
122 | 127 | } |
123 | 128 | |
124 | - foreach ($this->style as $style => $tokens) { |
|
125 | - if (\in_array($token[0], $tokens)) { |
|
129 | + foreach ($this->style as $style => $tokens) |
|
130 | + { |
|
131 | + if (\in_array($token[0], $tokens)) |
|
132 | + { |
|
126 | 133 | return $style; |
127 | 134 | } |
128 | 135 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | |
19 | 19 | public function line(int $number, string $code, bool $target = false): string |
20 | 20 | { |
21 | - if ($target) { |
|
21 | + if ($target){ |
|
22 | 22 | return \sprintf( |
23 | 23 | ">%s %s\n", |
24 | 24 | \str_pad((string)$number, 4, ' ', STR_PAD_LEFT), |
@@ -18,7 +18,8 @@ |
||
18 | 18 | |
19 | 19 | public function line(int $number, string $code, bool $target = false): string |
20 | 20 | { |
21 | - if ($target) { |
|
21 | + if ($target) |
|
22 | + { |
|
22 | 23 | return \sprintf( |
23 | 24 | ">%s %s\n", |
24 | 25 | \str_pad((string)$number, 4, ' ', STR_PAD_LEFT), |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | } |
44 | 44 | } |
45 | 45 | '), |
46 | - preg_replace('/\s+/', '', (string) $enum) |
|
46 | + preg_replace('/\s+/', '', (string)$enum) |
|
47 | 47 | ); |
48 | 48 | } |
49 | 49 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $enum = new EnumDeclaration('MyEnum'); |
156 | 156 | $enum->addImplement(\Countable::class)->addComment("Description of enum.\nSecond line\n"); |
157 | 157 | $enum->addCase('First', 'first'); |
158 | - $enum->addCase('Second', 'second');; |
|
158 | + $enum->addCase('Second', 'second'); ; |
|
159 | 159 | |
160 | 160 | $this->assertSame($expect, preg_replace('/\s+/', '', $enum->render())); |
161 | 161 | $this->assertSame($expect, preg_replace('/\s+/', '', $enum->__toString())); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | final class MyClass extends Spiral\Tests\Reactor\ClassDeclarationTest implements Countable |
30 | 30 | { |
31 | 31 | }'), |
32 | - preg_replace('/\s+/', '', (string) $declaration) |
|
32 | + preg_replace('/\s+/', '', (string)$declaration) |
|
33 | 33 | ); |
34 | 34 | } |
35 | 35 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | #[Foo\Cached(mode: true)] |
79 | 79 | public const WITH_ATTRIBUTE = \'attr\'; |
80 | 80 | }'), |
81 | - preg_replace('/\s+/', '', (string) $declaration) |
|
81 | + preg_replace('/\s+/', '', (string)$declaration) |
|
82 | 82 | ); |
83 | 83 | } |
84 | 84 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | return count($items ?: $this->items); |
112 | 112 | } |
113 | 113 | }'), |
114 | - preg_replace('/\s+/', '', (string) $declaration) |
|
114 | + preg_replace('/\s+/', '', (string)$declaration) |
|
115 | 115 | ); |
116 | 116 | } |
117 | 117 |
@@ -42,15 +42,15 @@ |
||
42 | 42 | |
43 | 43 | $declaration |
44 | 44 | ->addConstant('PRIVATE', 123) |
45 | - ->setVisibility(Partial\Visibility::PRIVATE); |
|
45 | + ->setVisibility(Partial\Visibility::private); |
|
46 | 46 | |
47 | 47 | $declaration |
48 | 48 | ->addConstant('PROTECTED', 456) |
49 | - ->setVisibility(Partial\Visibility::PROTECTED); |
|
49 | + ->setVisibility(Partial\Visibility::protected); |
|
50 | 50 | |
51 | 51 | $declaration |
52 | 52 | ->addConstant('PUBLIC', 789) |
53 | - ->setVisibility(Partial\Visibility::PUBLIC); |
|
53 | + ->setVisibility(Partial\Visibility::public); |
|
54 | 54 | |
55 | 55 | $declaration |
56 | 56 | ->addConstant('WITH_COMMENT', 'foo') |
@@ -65,38 +65,38 @@ |
||
65 | 65 | $property = new Property('foo'); |
66 | 66 | $this->assertNull($property->getVisibility()); |
67 | 67 | |
68 | - $property->setVisibility(Visibility::PUBLIC); |
|
69 | - $this->assertSame(Visibility::PUBLIC, $property->getVisibility()); |
|
68 | + $property->setVisibility(Visibility::public); |
|
69 | + $this->assertSame(Visibility::public, $property->getVisibility()); |
|
70 | 70 | $this->assertTrue($property->isPublic()); |
71 | 71 | $this->assertFalse($property->isProtected()); |
72 | 72 | $this->assertFalse($property->isPrivate()); |
73 | 73 | |
74 | - $property->setVisibility(Visibility::PROTECTED); |
|
75 | - $this->assertSame(Visibility::PROTECTED, $property->getVisibility()); |
|
74 | + $property->setVisibility(Visibility::protected); |
|
75 | + $this->assertSame(Visibility::protected, $property->getVisibility()); |
|
76 | 76 | $this->assertFalse($property->isPublic()); |
77 | 77 | $this->assertTrue($property->isProtected()); |
78 | 78 | $this->assertFalse($property->isPrivate()); |
79 | 79 | |
80 | - $property->setVisibility(Visibility::PRIVATE); |
|
81 | - $this->assertSame(Visibility::PRIVATE, $property->getVisibility()); |
|
80 | + $property->setVisibility(Visibility::private); |
|
81 | + $this->assertSame(Visibility::private, $property->getVisibility()); |
|
82 | 82 | $this->assertFalse($property->isPublic()); |
83 | 83 | $this->assertFalse($property->isProtected()); |
84 | 84 | $this->assertTrue($property->isPrivate()); |
85 | 85 | |
86 | 86 | $property->setPublic(); |
87 | - $this->assertSame(Visibility::PUBLIC, $property->getVisibility()); |
|
87 | + $this->assertSame(Visibility::public, $property->getVisibility()); |
|
88 | 88 | $this->assertTrue($property->isPublic()); |
89 | 89 | $this->assertFalse($property->isProtected()); |
90 | 90 | $this->assertFalse($property->isPrivate()); |
91 | 91 | |
92 | 92 | $property->setProtected(); |
93 | - $this->assertSame(Visibility::PROTECTED, $property->getVisibility()); |
|
93 | + $this->assertSame(Visibility::protected, $property->getVisibility()); |
|
94 | 94 | $this->assertFalse($property->isPublic()); |
95 | 95 | $this->assertTrue($property->isProtected()); |
96 | 96 | $this->assertFalse($property->isPrivate()); |
97 | 97 | |
98 | 98 | $property->setPrivate(); |
99 | - $this->assertSame(Visibility::PRIVATE, $property->getVisibility()); |
|
99 | + $this->assertSame(Visibility::private, $property->getVisibility()); |
|
100 | 100 | $this->assertFalse($property->isPublic()); |
101 | 101 | $this->assertFalse($property->isProtected()); |
102 | 102 | $this->assertTrue($property->isPrivate()); |
@@ -139,38 +139,38 @@ |
||
139 | 139 | $method = new Method('test'); |
140 | 140 | $this->assertNull($method->getVisibility()); |
141 | 141 | |
142 | - $method->setVisibility(Visibility::PUBLIC); |
|
143 | - $this->assertSame(Visibility::PUBLIC, $method->getVisibility()); |
|
142 | + $method->setVisibility(Visibility::public); |
|
143 | + $this->assertSame(Visibility::public, $method->getVisibility()); |
|
144 | 144 | $this->assertTrue($method->isPublic()); |
145 | 145 | $this->assertFalse($method->isProtected()); |
146 | 146 | $this->assertFalse($method->isPrivate()); |
147 | 147 | |
148 | - $method->setVisibility(Visibility::PROTECTED); |
|
149 | - $this->assertSame(Visibility::PROTECTED, $method->getVisibility()); |
|
148 | + $method->setVisibility(Visibility::protected); |
|
149 | + $this->assertSame(Visibility::protected, $method->getVisibility()); |
|
150 | 150 | $this->assertFalse($method->isPublic()); |
151 | 151 | $this->assertTrue($method->isProtected()); |
152 | 152 | $this->assertFalse($method->isPrivate()); |
153 | 153 | |
154 | - $method->setVisibility(Visibility::PRIVATE); |
|
155 | - $this->assertSame(Visibility::PRIVATE, $method->getVisibility()); |
|
154 | + $method->setVisibility(Visibility::private); |
|
155 | + $this->assertSame(Visibility::private, $method->getVisibility()); |
|
156 | 156 | $this->assertFalse($method->isPublic()); |
157 | 157 | $this->assertFalse($method->isProtected()); |
158 | 158 | $this->assertTrue($method->isPrivate()); |
159 | 159 | |
160 | 160 | $method->setPublic(); |
161 | - $this->assertSame(Visibility::PUBLIC, $method->getVisibility()); |
|
161 | + $this->assertSame(Visibility::public, $method->getVisibility()); |
|
162 | 162 | $this->assertTrue($method->isPublic()); |
163 | 163 | $this->assertFalse($method->isProtected()); |
164 | 164 | $this->assertFalse($method->isPrivate()); |
165 | 165 | |
166 | 166 | $method->setProtected(); |
167 | - $this->assertSame(Visibility::PROTECTED, $method->getVisibility()); |
|
167 | + $this->assertSame(Visibility::protected, $method->getVisibility()); |
|
168 | 168 | $this->assertFalse($method->isPublic()); |
169 | 169 | $this->assertTrue($method->isProtected()); |
170 | 170 | $this->assertFalse($method->isPrivate()); |
171 | 171 | |
172 | 172 | $method->setPrivate(); |
173 | - $this->assertSame(Visibility::PRIVATE, $method->getVisibility()); |
|
173 | + $this->assertSame(Visibility::private, $method->getVisibility()); |
|
174 | 174 | $this->assertFalse($method->isPublic()); |
175 | 175 | $this->assertFalse($method->isProtected()); |
176 | 176 | $this->assertTrue($method->isPrivate()); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | |
179 | 179 | public function testStatic(): void |
180 | 180 | { |
181 | - $method = new Method('test');; |
|
181 | + $method = new Method('test'); ; |
|
182 | 182 | |
183 | 183 | $this->assertFalse($method->isStatic()); |
184 | 184 | |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | |
195 | 195 | public function testFinal(): void |
196 | 196 | { |
197 | - $method = new Method('test');; |
|
197 | + $method = new Method('test'); ; |
|
198 | 198 | |
199 | 199 | $this->assertFalse($method->isFinal()); |
200 | 200 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | |
211 | 211 | public function testAbstract(): void |
212 | 212 | { |
213 | - $method = new Method('test');; |
|
213 | + $method = new Method('test'); ; |
|
214 | 214 | |
215 | 215 | $this->assertFalse($method->isAbstract()); |
216 | 216 |