@@ -25,7 +25,7 @@ |
||
25 | 25 | |
26 | 26 | $this->container = new Container(); |
27 | 27 | $this->container->bind(Tokenizer::class, $this->getTokenizer([ |
28 | - 'scopes' => ['foo' => ['directories' => [__DIR__ . '/Enums/Inner'], 'exclude' => []]], |
|
28 | + 'scopes' => ['foo' => ['directories' => [__DIR__.'/Enums/Inner'], 'exclude' => []]], |
|
29 | 29 | ])); |
30 | 30 | $this->container->bindSingleton(ScopedEnumsInterface::class, ScopedEnumLocator::class); |
31 | 31 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | |
26 | 26 | $this->container = new Container(); |
27 | 27 | $this->container->bind(Tokenizer::class, $this->getTokenizer(['scopes' => [ |
28 | - 'foo' => ['directories' => [__DIR__ . '/Interfaces/Inner'], 'exclude' => []], |
|
28 | + 'foo' => ['directories' => [__DIR__.'/Interfaces/Inner'], 'exclude' => []], |
|
29 | 29 | ]])); |
30 | 30 | $this->container->bindSingleton(ScopedInterfacesInterface::class, ScopedInterfaceLocator::class); |
31 | 31 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | { |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - if (!\class_exists(Message::class)) { |
|
17 | + if (!\class_exists(Message::class)){ |
|
18 | 18 | throw new SerializerException('Package `google/protobuf` is not installed.'); |
19 | 19 | } |
20 | 20 | } |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @throws InvalidArgumentException |
24 | 24 | */ |
25 | - public function serialize(mixed $payload): string|\Stringable |
|
25 | + public function serialize(mixed $payload): string | \Stringable |
|
26 | 26 | { |
27 | - if (!$payload instanceof Message) { |
|
27 | + if (!$payload instanceof Message){ |
|
28 | 28 | throw new InvalidArgumentException(\sprintf( |
29 | 29 | 'Payload must be of type `%s`, received `%s`.', |
30 | 30 | Message::class, |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | * @throws UnserializeException |
40 | 40 | * @throws InvalidArgumentException |
41 | 41 | */ |
42 | - public function unserialize(\Stringable|string $payload, object|string|null $type = null): mixed |
|
42 | + public function unserialize(\Stringable | string $payload, object | string | null $type = null): mixed |
|
43 | 43 | { |
44 | - if (\is_object($type)) { |
|
44 | + if (\is_object($type)){ |
|
45 | 45 | $type = $type::class; |
46 | 46 | } |
47 | 47 | |
48 | - if ($type === null || !\class_exists($type) || !\is_a($type, Message::class, true)) { |
|
48 | + if ($type === null || !\class_exists($type) || !\is_a($type, Message::class, true)){ |
|
49 | 49 | throw new InvalidArgumentException(\sprintf( |
50 | 50 | 'Parameter `$type` must be of type: `%s`, received `%s`.', |
51 | 51 | Message::class, |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | |
56 | 56 | $object = new $type(); |
57 | 57 | |
58 | - try { |
|
59 | - $object->mergeFromString((string) $payload); |
|
60 | - } catch (\Throwable $e) { |
|
58 | + try{ |
|
59 | + $object->mergeFromString((string)$payload); |
|
60 | + }catch (\Throwable $e){ |
|
61 | 61 | throw new UnserializeException( |
62 | 62 | \sprintf('Failed to unserialize data: %s', $e->getMessage()), |
63 | 63 | $e->getCode(), |
@@ -14,7 +14,8 @@ discard block |
||
14 | 14 | { |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - if (!\class_exists(Message::class)) { |
|
17 | + if (!\class_exists(Message::class)) |
|
18 | + { |
|
18 | 19 | throw new SerializerException('Package `google/protobuf` is not installed.'); |
19 | 20 | } |
20 | 21 | } |
@@ -24,7 +25,8 @@ discard block |
||
24 | 25 | */ |
25 | 26 | public function serialize(mixed $payload): string|\Stringable |
26 | 27 | { |
27 | - if (!$payload instanceof Message) { |
|
28 | + if (!$payload instanceof Message) |
|
29 | + { |
|
28 | 30 | throw new InvalidArgumentException(\sprintf( |
29 | 31 | 'Payload must be of type `%s`, received `%s`.', |
30 | 32 | Message::class, |
@@ -41,11 +43,13 @@ discard block |
||
41 | 43 | */ |
42 | 44 | public function unserialize(\Stringable|string $payload, object|string|null $type = null): mixed |
43 | 45 | { |
44 | - if (\is_object($type)) { |
|
46 | + if (\is_object($type)) |
|
47 | + { |
|
45 | 48 | $type = $type::class; |
46 | 49 | } |
47 | 50 | |
48 | - if ($type === null || !\class_exists($type) || !\is_a($type, Message::class, true)) { |
|
51 | + if ($type === null || !\class_exists($type) || !\is_a($type, Message::class, true)) |
|
52 | + { |
|
49 | 53 | throw new InvalidArgumentException(\sprintf( |
50 | 54 | 'Parameter `$type` must be of type: `%s`, received `%s`.', |
51 | 55 | Message::class, |
@@ -55,9 +59,12 @@ discard block |
||
55 | 59 | |
56 | 60 | $object = new $type(); |
57 | 61 | |
58 | - try { |
|
62 | + try |
|
63 | + { |
|
59 | 64 | $object->mergeFromString((string) $payload); |
60 | - } catch (\Throwable $e) { |
|
65 | + } |
|
66 | + catch (\Throwable $e) |
|
67 | + { |
|
61 | 68 | throw new UnserializeException( |
62 | 69 | \sprintf('Failed to unserialize data: %s', $e->getMessage()), |
63 | 70 | $e->getCode(), |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | ->method('getArgument') |
38 | 38 | ->willReturnOnConsecutiveCalls(5, 'foo', ['foo', 'bar'], 0.5, true); |
39 | 39 | |
40 | - $command = new #[AsCommand('foo')] class extends Command { |
|
40 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
41 | 41 | #[Argument] |
42 | 42 | public int $intVal; |
43 | 43 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | ->expects($this->never()) |
77 | 77 | ->method('getArgument'); |
78 | 78 | |
79 | - $command = new #[AsCommand('foo')] class extends Command { |
|
79 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
80 | 80 | #[Argument] |
81 | 81 | public int $arg; |
82 | 82 | }; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | ->method('getOption') |
100 | 100 | ->willReturnOnConsecutiveCalls(5, 'foo', ['foo', 'bar'], 0.5, true, true); |
101 | 101 | |
102 | - $command = new #[AsCommand('foo')] class extends Command { |
|
102 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
103 | 103 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
104 | 104 | public int $intVal; |
105 | 105 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | ->method('getOption') |
143 | 143 | ->willReturnOnConsecutiveCalls(1, null, 0); |
144 | 144 | |
145 | - $command = new #[AsCommand('foo')] class extends Command { |
|
145 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
146 | 146 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
147 | 147 | public Status $required; |
148 | 148 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | $input->expects($this->once())->method('hasOption')->willReturn(true); |
167 | 167 | $input->expects($this->once())->method('getOption')->willReturn('foo'); |
168 | 168 | |
169 | - $command = new #[AsCommand('foo')] class extends Command { |
|
169 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
170 | 170 | #[Option] |
171 | 171 | public Status $status; |
172 | 172 | }; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | ->expects($this->never()) |
189 | 189 | ->method('getOption'); |
190 | 190 | |
191 | - $command = new #[AsCommand('foo')] class extends Command { |
|
191 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
192 | 192 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
193 | 193 | public int $option; |
194 | 194 | }; |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | ->method('getOption') |
213 | 213 | ->willReturn(null); |
214 | 214 | |
215 | - $command = new #[AsCommand('foo')] class extends Command { |
|
215 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
216 | 216 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
217 | 217 | public int $option; |
218 | 218 | }; |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | ->method('getOption') |
236 | 236 | ->willReturn(null); |
237 | 237 | |
238 | - $command = new #[AsCommand('foo')] class extends Command { |
|
238 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
239 | 239 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
240 | 240 | public ?int $intVal; |
241 | 241 | }; |
@@ -37,7 +37,8 @@ discard block |
||
37 | 37 | ->method('getArgument') |
38 | 38 | ->willReturnOnConsecutiveCalls(5, 'foo', ['foo', 'bar'], 0.5, true); |
39 | 39 | |
40 | - $command = new #[AsCommand('foo')] class extends Command { |
|
40 | + $command = new #[AsCommand('foo')] class extends Command |
|
41 | + { |
|
41 | 42 | #[Argument] |
42 | 43 | public int $intVal; |
43 | 44 | |
@@ -76,7 +77,8 @@ discard block |
||
76 | 77 | ->expects($this->never()) |
77 | 78 | ->method('getArgument'); |
78 | 79 | |
79 | - $command = new #[AsCommand('foo')] class extends Command { |
|
80 | + $command = new #[AsCommand('foo')] class extends Command |
|
81 | + { |
|
80 | 82 | #[Argument] |
81 | 83 | public int $arg; |
82 | 84 | }; |
@@ -99,7 +101,8 @@ discard block |
||
99 | 101 | ->method('getOption') |
100 | 102 | ->willReturnOnConsecutiveCalls(5, 'foo', ['foo', 'bar'], 0.5, true, true); |
101 | 103 | |
102 | - $command = new #[AsCommand('foo')] class extends Command { |
|
104 | + $command = new #[AsCommand('foo')] class extends Command |
|
105 | + { |
|
103 | 106 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
104 | 107 | public int $intVal; |
105 | 108 | |
@@ -142,7 +145,8 @@ discard block |
||
142 | 145 | ->method('getOption') |
143 | 146 | ->willReturnOnConsecutiveCalls(1, null, 0); |
144 | 147 | |
145 | - $command = new #[AsCommand('foo')] class extends Command { |
|
148 | + $command = new #[AsCommand('foo')] class extends Command |
|
149 | + { |
|
146 | 150 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
147 | 151 | public Status $required; |
148 | 152 | |
@@ -166,7 +170,8 @@ discard block |
||
166 | 170 | $input->expects($this->once())->method('hasOption')->willReturn(true); |
167 | 171 | $input->expects($this->once())->method('getOption')->willReturn('foo'); |
168 | 172 | |
169 | - $command = new #[AsCommand('foo')] class extends Command { |
|
173 | + $command = new #[AsCommand('foo')] class extends Command |
|
174 | + { |
|
170 | 175 | #[Option] |
171 | 176 | public Status $status; |
172 | 177 | }; |
@@ -188,7 +193,8 @@ discard block |
||
188 | 193 | ->expects($this->never()) |
189 | 194 | ->method('getOption'); |
190 | 195 | |
191 | - $command = new #[AsCommand('foo')] class extends Command { |
|
196 | + $command = new #[AsCommand('foo')] class extends Command |
|
197 | + { |
|
192 | 198 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
193 | 199 | public int $option; |
194 | 200 | }; |
@@ -212,7 +218,8 @@ discard block |
||
212 | 218 | ->method('getOption') |
213 | 219 | ->willReturn(null); |
214 | 220 | |
215 | - $command = new #[AsCommand('foo')] class extends Command { |
|
221 | + $command = new #[AsCommand('foo')] class extends Command |
|
222 | + { |
|
216 | 223 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
217 | 224 | public int $option; |
218 | 225 | }; |
@@ -235,7 +242,8 @@ discard block |
||
235 | 242 | ->method('getOption') |
236 | 243 | ->willReturn(null); |
237 | 244 | |
238 | - $command = new #[AsCommand('foo')] class extends Command { |
|
245 | + $command = new #[AsCommand('foo')] class extends Command |
|
246 | + { |
|
239 | 247 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
240 | 248 | public ?int $intVal; |
241 | 249 | }; |
@@ -48,23 +48,23 @@ |
||
48 | 48 | |
49 | 49 | private function configureExtensions(ConsoleBootloader $console, ContainerInterface $container): void |
50 | 50 | { |
51 | - if ($container->has(TranslatorInterface::class)) { |
|
51 | + if ($container->has(TranslatorInterface::class)){ |
|
52 | 52 | $this->configureTranslator($console); |
53 | 53 | } |
54 | 54 | |
55 | - if ($container->has(ViewsInterface::class)) { |
|
55 | + if ($container->has(ViewsInterface::class)){ |
|
56 | 56 | $this->configureViews($console); |
57 | 57 | } |
58 | 58 | |
59 | - if ($container->has(EncryptionInterface::class)) { |
|
59 | + if ($container->has(EncryptionInterface::class)){ |
|
60 | 60 | $this->configureEncrypter($console); |
61 | 61 | } |
62 | 62 | |
63 | - if ($container->has(RouterInterface::class)) { |
|
63 | + if ($container->has(RouterInterface::class)){ |
|
64 | 64 | $console->addCommand(Router\ListCommand::class); |
65 | 65 | } |
66 | 66 | |
67 | - if ($container->has(ClassesInterface::class)) { |
|
67 | + if ($container->has(ClassesInterface::class)){ |
|
68 | 68 | $console->addCommand(Tokenizer\InfoCommand::class); |
69 | 69 | $console->addCommand(Tokenizer\ValidateCommand::class); |
70 | 70 | } |
@@ -48,23 +48,28 @@ |
||
48 | 48 | |
49 | 49 | private function configureExtensions(ConsoleBootloader $console, ContainerInterface $container): void |
50 | 50 | { |
51 | - if ($container->has(TranslatorInterface::class)) { |
|
51 | + if ($container->has(TranslatorInterface::class)) |
|
52 | + { |
|
52 | 53 | $this->configureTranslator($console); |
53 | 54 | } |
54 | 55 | |
55 | - if ($container->has(ViewsInterface::class)) { |
|
56 | + if ($container->has(ViewsInterface::class)) |
|
57 | + { |
|
56 | 58 | $this->configureViews($console); |
57 | 59 | } |
58 | 60 | |
59 | - if ($container->has(EncryptionInterface::class)) { |
|
61 | + if ($container->has(EncryptionInterface::class)) |
|
62 | + { |
|
60 | 63 | $this->configureEncrypter($console); |
61 | 64 | } |
62 | 65 | |
63 | - if ($container->has(RouterInterface::class)) { |
|
66 | + if ($container->has(RouterInterface::class)) |
|
67 | + { |
|
64 | 68 | $console->addCommand(Router\ListCommand::class); |
65 | 69 | } |
66 | 70 | |
67 | - if ($container->has(ClassesInterface::class)) { |
|
71 | + if ($container->has(ClassesInterface::class)) |
|
72 | + { |
|
68 | 73 | $console->addCommand(Tokenizer\InfoCommand::class); |
69 | 74 | $console->addCommand(Tokenizer\ValidateCommand::class); |
70 | 75 | } |
@@ -12,7 +12,7 @@ |
||
12 | 12 | */ |
13 | 13 | class ExtendedContextInjector implements InjectorInterface |
14 | 14 | { |
15 | - public function createInjection(\ReflectionClass $class, \ReflectionParameter|string|null $context = null): object |
|
15 | + public function createInjection(\ReflectionClass $class, \ReflectionParameter | string | null $context = null): object |
|
16 | 16 | { |
17 | 17 | return (object)['context' => $context]; |
18 | 18 | } |
@@ -23,7 +23,8 @@ |
||
23 | 23 | $listeners = \method_exists($registry, 'getListenerClasses') ? $registry->getListenerClasses() : []; |
24 | 24 | |
25 | 25 | $grid = $this->table(['Listener', 'Suggestion']); |
26 | - foreach ($listeners as $class) { |
|
26 | + foreach ($listeners as $class) |
|
27 | + { |
|
27 | 28 | $ref = new \ReflectionClass($class); |
28 | 29 | $attribute = $reader->firstClassMetadata($ref, AbstractTarget::class); |
29 | 30 | $suggestion = match (true) { |
@@ -23,16 +23,16 @@ |
||
23 | 23 | $listeners = \method_exists($registry, 'getListenerClasses') ? $registry->getListenerClasses() : []; |
24 | 24 | |
25 | 25 | $grid = $this->table(['Listener', 'Suggestion']); |
26 | - foreach ($listeners as $class) { |
|
26 | + foreach ($listeners as $class){ |
|
27 | 27 | $ref = new \ReflectionClass($class); |
28 | 28 | $attribute = $reader->firstClassMetadata($ref, AbstractTarget::class); |
29 | 29 | $suggestion = match (true) { |
30 | - $attribute === null => 'Add <comment>#[TargetClass]</comment> or ' . |
|
30 | + $attribute === null => 'Add <comment>#[TargetClass]</comment> or '. |
|
31 | 31 | '<comment>#[TargetAttribute]</comment> attribute to the listener', |
32 | 32 | default => '<fg=green> ✓ </>', |
33 | 33 | }; |
34 | 34 | $grid->addRow([ |
35 | - $class . "\n" . \sprintf( |
|
35 | + $class."\n".\sprintf( |
|
36 | 36 | '<fg=gray>%s</>', |
37 | 37 | \str_replace([$dirs->get('root'), '\\'], ['', '/'], $ref->getFileName()), |
38 | 38 | ), |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | ClassesLoaderInterface $loader, |
131 | 131 | ListenerInvoker $invoker, |
132 | 132 | ): void { |
133 | - if ($config->isLoadClassesEnabled()) { |
|
133 | + if ($config->isLoadClassesEnabled()){ |
|
134 | 134 | $this->loadReflections($invoker, $classes->getClasses(...), $loader->loadClasses(...)); |
135 | 135 | } |
136 | 136 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | EnumsLoaderInterface $loader, |
142 | 142 | ListenerInvoker $invoker, |
143 | 143 | ): void { |
144 | - if ($config->isLoadEnumsEnabled()) { |
|
144 | + if ($config->isLoadEnumsEnabled()){ |
|
145 | 145 | $this->loadReflections($invoker, $enums->getEnums(...), $loader->loadEnums(...)); |
146 | 146 | } |
147 | 147 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | InterfacesLoaderInterface $loader, |
153 | 153 | ListenerInvoker $invoker, |
154 | 154 | ): void { |
155 | - if ($config->isLoadInterfacesEnabled()) { |
|
155 | + if ($config->isLoadInterfacesEnabled()){ |
|
156 | 156 | $this->loadReflections($invoker, $interfaces->getInterfaces(...), $loader->loadInterfaces(...)); |
157 | 157 | } |
158 | 158 | } |
@@ -170,15 +170,15 @@ discard block |
||
170 | 170 | |
171 | 171 | // First, we check if the listener has been cached. If it has, we will load the classes/enums/interfaces |
172 | 172 | // from the cache. |
173 | - foreach ($listeners as $i => $listener) { |
|
174 | - if ($loader($listener)) { |
|
173 | + foreach ($listeners as $i => $listener){ |
|
174 | + if ($loader($listener)){ |
|
175 | 175 | unset($listeners[$i]); |
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | 179 | // If there are no listeners left, we don't need to use static analysis at all and save |
180 | 180 | // valuable time. |
181 | - if ($listeners === []) { |
|
181 | + if ($listeners === []){ |
|
182 | 182 | return; |
183 | 183 | } |
184 | 184 | |
@@ -186,14 +186,14 @@ discard block |
||
186 | 186 | // Please note that this is a very expensive operation and should be avoided if possible. |
187 | 187 | // Use #[TargetClass] or #[TargetAttribute] attributes in your listeners to cache the classes/enums/interfaces. |
188 | 188 | $classes = $reflections(); |
189 | - foreach ($listeners as $listener) { |
|
189 | + foreach ($listeners as $listener){ |
|
190 | 190 | $invoker->invoke($listener, $classes); |
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | 194 | private function finalizeListeners(): void |
195 | 195 | { |
196 | - foreach ($this->listeners as $listener) { |
|
196 | + foreach ($this->listeners as $listener){ |
|
197 | 197 | $listener->finalize(); |
198 | 198 | } |
199 | 199 | // We don't need the listeners anymore, so we will clear them from memory. |
@@ -130,7 +130,8 @@ discard block |
||
130 | 130 | ClassesLoaderInterface $loader, |
131 | 131 | ListenerInvoker $invoker, |
132 | 132 | ): void { |
133 | - if ($config->isLoadClassesEnabled()) { |
|
133 | + if ($config->isLoadClassesEnabled()) |
|
134 | + { |
|
134 | 135 | $this->loadReflections($invoker, $classes->getClasses(...), $loader->loadClasses(...)); |
135 | 136 | } |
136 | 137 | } |
@@ -141,7 +142,8 @@ discard block |
||
141 | 142 | EnumsLoaderInterface $loader, |
142 | 143 | ListenerInvoker $invoker, |
143 | 144 | ): void { |
144 | - if ($config->isLoadEnumsEnabled()) { |
|
145 | + if ($config->isLoadEnumsEnabled()) |
|
146 | + { |
|
145 | 147 | $this->loadReflections($invoker, $enums->getEnums(...), $loader->loadEnums(...)); |
146 | 148 | } |
147 | 149 | } |
@@ -152,7 +154,8 @@ discard block |
||
152 | 154 | InterfacesLoaderInterface $loader, |
153 | 155 | ListenerInvoker $invoker, |
154 | 156 | ): void { |
155 | - if ($config->isLoadInterfacesEnabled()) { |
|
157 | + if ($config->isLoadInterfacesEnabled()) |
|
158 | + { |
|
156 | 159 | $this->loadReflections($invoker, $interfaces->getInterfaces(...), $loader->loadInterfaces(...)); |
157 | 160 | } |
158 | 161 | } |
@@ -170,15 +173,18 @@ discard block |
||
170 | 173 | |
171 | 174 | // First, we check if the listener has been cached. If it has, we will load the classes/enums/interfaces |
172 | 175 | // from the cache. |
173 | - foreach ($listeners as $i => $listener) { |
|
174 | - if ($loader($listener)) { |
|
176 | + foreach ($listeners as $i => $listener) |
|
177 | + { |
|
178 | + if ($loader($listener)) |
|
179 | + { |
|
175 | 180 | unset($listeners[$i]); |
176 | 181 | } |
177 | 182 | } |
178 | 183 | |
179 | 184 | // If there are no listeners left, we don't need to use static analysis at all and save |
180 | 185 | // valuable time. |
181 | - if ($listeners === []) { |
|
186 | + if ($listeners === []) |
|
187 | + { |
|
182 | 188 | return; |
183 | 189 | } |
184 | 190 | |
@@ -186,14 +192,16 @@ discard block |
||
186 | 192 | // Please note that this is a very expensive operation and should be avoided if possible. |
187 | 193 | // Use #[TargetClass] or #[TargetAttribute] attributes in your listeners to cache the classes/enums/interfaces. |
188 | 194 | $classes = $reflections(); |
189 | - foreach ($listeners as $listener) { |
|
195 | + foreach ($listeners as $listener) |
|
196 | + { |
|
190 | 197 | $invoker->invoke($listener, $classes); |
191 | 198 | } |
192 | 199 | } |
193 | 200 | |
194 | 201 | private function finalizeListeners(): void |
195 | 202 | { |
196 | - foreach ($this->listeners as $listener) { |
|
203 | + foreach ($this->listeners as $listener) |
|
204 | + { |
|
197 | 205 | $listener->finalize(); |
198 | 206 | } |
199 | 207 | // We don't need the listeners anymore, so we will clear them from memory. |
@@ -47,9 +47,12 @@ discard block |
||
47 | 47 | |
48 | 48 | public function getRenderer(?string $format = null): ?ExceptionRendererInterface |
49 | 49 | { |
50 | - if ($format !== null) { |
|
51 | - foreach ($this->renderers as $renderer) { |
|
52 | - if ($renderer->canRender($format)) { |
|
50 | + if ($format !== null) |
|
51 | + { |
|
52 | + foreach ($this->renderers as $renderer) |
|
53 | + { |
|
54 | + if ($renderer->canRender($format)) |
|
55 | + { |
|
53 | 56 | return $renderer; |
54 | 57 | } |
55 | 58 | } |
@@ -72,18 +75,26 @@ discard block |
||
72 | 75 | |
73 | 76 | public function report(\Throwable $exception): void |
74 | 77 | { |
75 | - if ($this->shouldNotReport($exception)) { |
|
78 | + if ($this->shouldNotReport($exception)) |
|
79 | + { |
|
76 | 80 | return; |
77 | 81 | } |
78 | 82 | |
79 | - foreach ($this->reporters as $reporter) { |
|
80 | - try { |
|
81 | - if ($reporter instanceof ExceptionReporterInterface) { |
|
83 | + foreach ($this->reporters as $reporter) |
|
84 | + { |
|
85 | + try |
|
86 | + { |
|
87 | + if ($reporter instanceof ExceptionReporterInterface) |
|
88 | + { |
|
82 | 89 | $reporter->report($exception); |
83 | - } else { |
|
90 | + } |
|
91 | + else |
|
92 | + { |
|
84 | 93 | $reporter($exception); |
85 | 94 | } |
86 | - } catch (\Throwable) { |
|
95 | + } |
|
96 | + catch (\Throwable) |
|
97 | + { |
|
87 | 98 | // Do nothing |
88 | 99 | } |
89 | 100 | } |
@@ -91,10 +102,13 @@ discard block |
||
91 | 102 | |
92 | 103 | public function handleGlobalException(\Throwable $e): void |
93 | 104 | { |
94 | - if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)) { |
|
105 | + if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)) |
|
106 | + { |
|
95 | 107 | $this->output ??= \defined('STDERR') ? \STDERR : \fopen('php://stderr', 'wb+'); |
96 | 108 | $format = 'cli'; |
97 | - } else { |
|
109 | + } |
|
110 | + else |
|
111 | + { |
|
98 | 112 | $this->output ??= \defined('STDOUT') ? \STDOUT : \fopen('php://stdout', 'wb+'); |
99 | 113 | $format = 'html'; |
100 | 114 | } |
@@ -103,9 +117,12 @@ discard block |
||
103 | 117 | $this->report($e); |
104 | 118 | |
105 | 119 | // There is possible an exception on the application termination |
106 | - try { |
|
120 | + try |
|
121 | + { |
|
107 | 122 | \fwrite($this->output, $this->render($e, verbosity: $this->verbosity, format: $format)); |
108 | - } catch (\Throwable) { |
|
123 | + } |
|
124 | + catch (\Throwable) |
|
125 | + { |
|
109 | 126 | $this->output = null; |
110 | 127 | } |
111 | 128 | } |
@@ -147,13 +164,17 @@ discard block |
||
147 | 164 | */ |
148 | 165 | protected function handleShutdown(): void |
149 | 166 | { |
150 | - if (empty($error = \error_get_last())) { |
|
167 | + if (empty($error = \error_get_last())) |
|
168 | + { |
|
151 | 169 | return; |
152 | 170 | } |
153 | 171 | |
154 | - try { |
|
172 | + try |
|
173 | + { |
|
155 | 174 | $this->handleError($error['type'], $error['message'], $error['file'], $error['line']); |
156 | - } catch (\Throwable $e) { |
|
175 | + } |
|
176 | + catch (\Throwable $e) |
|
177 | + { |
|
157 | 178 | $this->handleGlobalException($e); |
158 | 179 | } |
159 | 180 | } |
@@ -169,7 +190,8 @@ discard block |
||
169 | 190 | string $errfile = '', |
170 | 191 | int $errline = 0, |
171 | 192 | ): bool { |
172 | - if (!(\error_reporting() & $errno)) { |
|
193 | + if (!(\error_reporting() & $errno)) |
|
194 | + { |
|
173 | 195 | return false; |
174 | 196 | } |
175 | 197 | |
@@ -183,8 +205,10 @@ discard block |
||
183 | 205 | |
184 | 206 | protected function shouldNotReport(\Throwable $exception): bool |
185 | 207 | { |
186 | - foreach ($this->nonReportableExceptions as $nonReportableException) { |
|
187 | - if ($exception instanceof $nonReportableException) { |
|
208 | + foreach ($this->nonReportableExceptions as $nonReportableException) |
|
209 | + { |
|
210 | + if ($exception instanceof $nonReportableException) |
|
211 | + { |
|
188 | 212 | return true; |
189 | 213 | } |
190 | 214 | } |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | |
56 | 56 | public function getRenderer(?string $format = null): ?ExceptionRendererInterface |
57 | 57 | { |
58 | - if ($format !== null) { |
|
59 | - foreach ($this->renderers as $renderer) { |
|
60 | - if ($renderer->canRender($format)) { |
|
58 | + if ($format !== null){ |
|
59 | + foreach ($this->renderers as $renderer){ |
|
60 | + if ($renderer->canRender($format)){ |
|
61 | 61 | return $renderer; |
62 | 62 | } |
63 | 63 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | ?Verbosity $verbosity = null, |
71 | 71 | ?string $format = null, |
72 | 72 | ): string { |
73 | - return (string) $this->getRenderer($format)?->render($exception, $verbosity ?? $this->verbosity, $format); |
|
73 | + return (string)$this->getRenderer($format)?->render($exception, $verbosity ?? $this->verbosity, $format); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | public function canRender(string $format): bool |
@@ -80,18 +80,18 @@ discard block |
||
80 | 80 | |
81 | 81 | public function report(\Throwable $exception): void |
82 | 82 | { |
83 | - if ($this->shouldNotReport($exception)) { |
|
83 | + if ($this->shouldNotReport($exception)){ |
|
84 | 84 | return; |
85 | 85 | } |
86 | 86 | |
87 | - foreach ($this->reporters as $reporter) { |
|
88 | - try { |
|
89 | - if ($reporter instanceof ExceptionReporterInterface) { |
|
87 | + foreach ($this->reporters as $reporter){ |
|
88 | + try{ |
|
89 | + if ($reporter instanceof ExceptionReporterInterface){ |
|
90 | 90 | $reporter->report($exception); |
91 | - } else { |
|
91 | + }else{ |
|
92 | 92 | $reporter($exception); |
93 | 93 | } |
94 | - } catch (\Throwable) { |
|
94 | + }catch (\Throwable){ |
|
95 | 95 | // Do nothing |
96 | 96 | } |
97 | 97 | } |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | |
100 | 100 | public function handleGlobalException(\Throwable $e): void |
101 | 101 | { |
102 | - if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)) { |
|
102 | + if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)){ |
|
103 | 103 | $this->output ??= \defined('STDERR') ? \STDERR : \fopen('php://stderr', 'wb+'); |
104 | 104 | $format = 'cli'; |
105 | - } else { |
|
105 | + }else{ |
|
106 | 106 | $this->output ??= \defined('STDOUT') ? \STDOUT : \fopen('php://stdout', 'wb+'); |
107 | 107 | $format = 'html'; |
108 | 108 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | $this->report($e); |
112 | 112 | |
113 | 113 | // There is possible an exception on the application termination |
114 | - try { |
|
114 | + try{ |
|
115 | 115 | \fwrite($this->output, $this->render($e, verbosity: $this->verbosity, format: $format)); |
116 | - } catch (\Throwable) { |
|
116 | + }catch (\Throwable){ |
|
117 | 117 | $this->output = null; |
118 | 118 | } |
119 | 119 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | /** |
138 | 138 | * @param ExceptionReporterInterface|\Closure(\Throwable):void $reporter |
139 | 139 | */ |
140 | - public function addReporter(ExceptionReporterInterface|\Closure $reporter): void |
|
140 | + public function addReporter(ExceptionReporterInterface | \Closure $reporter): void |
|
141 | 141 | { |
142 | 142 | $this->reporters[] = $reporter; |
143 | 143 | } |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | */ |
156 | 156 | protected function handleShutdown(): void |
157 | 157 | { |
158 | - if (empty($error = \error_get_last())) { |
|
158 | + if (empty($error = \error_get_last())){ |
|
159 | 159 | return; |
160 | 160 | } |
161 | 161 | |
162 | - try { |
|
162 | + try{ |
|
163 | 163 | $this->handleError($error['type'], $error['message'], $error['file'], $error['line']); |
164 | - } catch (\Throwable $e) { |
|
164 | + }catch (\Throwable $e){ |
|
165 | 165 | $this->handleGlobalException($e); |
166 | 166 | } |
167 | 167 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | string $errfile = '', |
178 | 178 | int $errline = 0, |
179 | 179 | ): bool { |
180 | - if (!(\error_reporting() & $errno)) { |
|
180 | + if (!(\error_reporting() & $errno)){ |
|
181 | 181 | return false; |
182 | 182 | } |
183 | 183 | |
@@ -191,8 +191,8 @@ discard block |
||
191 | 191 | |
192 | 192 | protected function shouldNotReport(\Throwable $exception): bool |
193 | 193 | { |
194 | - foreach ($this->nonReportableExceptions as $nonReportableException) { |
|
195 | - if ($exception instanceof $nonReportableException) { |
|
194 | + foreach ($this->nonReportableExceptions as $nonReportableException){ |
|
195 | + if ($exception instanceof $nonReportableException){ |
|
196 | 196 | return true; |
197 | 197 | } |
198 | 198 | } |