Passed
Pull Request — master (#1190)
by Aleksei
20:19 queued 07:41
created
src/Boot/tests/Fixtures/SampleClass.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,4 +4,4 @@
 block discarded – undo
4 4
 
5 5
 namespace Spiral\Tests\Boot\Fixtures;
6 6
 
7
-class SampleClass implements SampleClassInterface {}
7
+class SampleClass implements SampleClassInterface{}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,4 +4,6 @@
 block discarded – undo
4 4
 
5 5
 namespace Spiral\Tests\Boot\Fixtures;
6 6
 
7
-class SampleClass implements SampleClassInterface {}
7
+class SampleClass implements SampleClassInterface
8
+{
9
+}
Please login to merge, or discard this patch.
src/Boot/tests/Fixtures/Attribute/SampleMethod.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,4 +5,4 @@
 block discarded – undo
5 5
 namespace Spiral\Tests\Boot\Fixtures\Attribute;
6 6
 
7 7
 #[\Attribute(\Attribute::TARGET_METHOD)]
8
-final class SampleMethod extends \Spiral\Boot\Attribute\AbstractMethod {}
8
+final class SampleMethod extends \Spiral\Boot\Attribute\AbstractMethod{}
Please login to merge, or discard this patch.
src/Boot/src/BootloadManager/DefaultInvokerStrategy.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
         private readonly InitializerInterface $initializer,
15 15
         private readonly InvokerInterface $invoker,
16 16
         private readonly ResolverInterface $resolver,
17
-    ) {}
17
+    ){}
18 18
 
19 19
     public function invokeBootloaders(
20 20
         array $classes,
@@ -25,16 +25,16 @@  discard block
 block discarded – undo
25 25
         /** @psalm-suppress TooManyArguments */
26 26
         $bootloaders = \iterator_to_array($this->initializer->init($classes, $useConfig));
27 27
 
28
-        foreach ($bootloaders as $data) {
29
-            foreach ($data['init_methods'] as $methodName) {
28
+        foreach ($bootloaders as $data){
29
+            foreach ($data['init_methods'] as $methodName){
30 30
                 $this->invokeBootloader($data['bootloader'], $methodName, $data['options']);
31 31
             }
32 32
         }
33 33
 
34 34
         $this->fireCallbacks($bootingCallbacks);
35 35
 
36
-        foreach ($bootloaders as $data) {
37
-            foreach ($data['boot_methods'] as $methodName) {
36
+        foreach ($bootloaders as $data){
37
+            foreach ($data['boot_methods'] as $methodName){
38 38
                 $this->invokeBootloader($data['bootloader'], $methodName, $data['options']);
39 39
             }
40 40
         }
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
     private function invokeBootloader(BootloaderInterface $bootloader, string $method, array $options): void
46 46
     {
47 47
         $refl = new \ReflectionClass($bootloader);
48
-        if (!$refl->hasMethod($method)) {
48
+        if (!$refl->hasMethod($method)){
49 49
             return;
50 50
         }
51 51
 
52 52
         $method = $refl->getMethod($method);
53 53
 
54 54
         $args = $this->resolver->resolveArguments($method);
55
-        if (!isset($args['boot'])) {
55
+        if (!isset($args['boot'])){
56 56
             $args['boot'] = $options;
57 57
         }
58 58
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
      */
65 65
     private function fireCallbacks(array $callbacks): void
66 66
     {
67
-        foreach ($callbacks as $callback) {
67
+        foreach ($callbacks as $callback){
68 68
             $this->invoker->invoke($callback);
69 69
         }
70 70
     }
Please login to merge, or discard this patch.
Braces   +16 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,7 +14,8 @@  discard block
 block discarded – undo
14 14
         private readonly InitializerInterface $initializer,
15 15
         private readonly InvokerInterface $invoker,
16 16
         private readonly ResolverInterface $resolver,
17
-    ) {}
17
+    ) {
18
+}
18 19
 
19 20
     public function invokeBootloaders(
20 21
         array $classes,
@@ -25,16 +26,20 @@  discard block
 block discarded – undo
25 26
         /** @psalm-suppress TooManyArguments */
26 27
         $bootloaders = \iterator_to_array($this->initializer->init($classes, $useConfig));
27 28
 
28
-        foreach ($bootloaders as $data) {
29
-            foreach ($data['init_methods'] as $methodName) {
29
+        foreach ($bootloaders as $data)
30
+        {
31
+            foreach ($data['init_methods'] as $methodName)
32
+            {
30 33
                 $this->invokeBootloader($data['bootloader'], $methodName, $data['options']);
31 34
             }
32 35
         }
33 36
 
34 37
         $this->fireCallbacks($bootingCallbacks);
35 38
 
36
-        foreach ($bootloaders as $data) {
37
-            foreach ($data['boot_methods'] as $methodName) {
39
+        foreach ($bootloaders as $data)
40
+        {
41
+            foreach ($data['boot_methods'] as $methodName)
42
+            {
38 43
                 $this->invokeBootloader($data['bootloader'], $methodName, $data['options']);
39 44
             }
40 45
         }
@@ -45,14 +50,16 @@  discard block
 block discarded – undo
45 50
     private function invokeBootloader(BootloaderInterface $bootloader, string $method, array $options): void
46 51
     {
47 52
         $refl = new \ReflectionClass($bootloader);
48
-        if (!$refl->hasMethod($method)) {
53
+        if (!$refl->hasMethod($method))
54
+        {
49 55
             return;
50 56
         }
51 57
 
52 58
         $method = $refl->getMethod($method);
53 59
 
54 60
         $args = $this->resolver->resolveArguments($method);
55
-        if (!isset($args['boot'])) {
61
+        if (!isset($args['boot']))
62
+        {
56 63
             $args['boot'] = $options;
57 64
         }
58 65
 
@@ -64,7 +71,8 @@  discard block
 block discarded – undo
64 71
      */
65 72
     private function fireCallbacks(array $callbacks): void
66 73
     {
67
-        foreach ($callbacks as $callback) {
74
+        foreach ($callbacks as $callback)
75
+        {
68 76
             $this->invoker->invoke($callback);
69 77
         }
70 78
     }
Please login to merge, or discard this patch.
src/Boot/src/AbstractKernel.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
         protected readonly ExceptionHandlerInterface $exceptionHandler,
79 79
         protected readonly BootloadManagerInterface $bootloader,
80 80
         array $directories,
81
-    ) {
81
+    ){
82 82
         $container->bindSingleton(ExceptionHandlerInterface::class, $exceptionHandler);
83 83
         $container->bindSingleton(ExceptionRendererInterface::class, $exceptionHandler);
84 84
         $container->bindSingleton(ExceptionReporterInterface::class, $exceptionHandler);
@@ -107,38 +107,38 @@  discard block
 block discarded – undo
107 107
     final public static function create(
108 108
         array $directories,
109 109
         bool $handleErrors = true,
110
-        ExceptionHandlerInterface|string|null $exceptionHandler = null,
110
+        ExceptionHandlerInterface | string | null $exceptionHandler = null,
111 111
         Container $container = new Container(),
112
-        BootloadManagerInterface|Autowire|null $bootloadManager = null,
112
+        BootloadManagerInterface | Autowire | null $bootloadManager = null,
113 113
     ): static {
114 114
         $exceptionHandler ??= ExceptionHandler::class;
115 115
 
116
-        if (\is_string($exceptionHandler)) {
116
+        if (\is_string($exceptionHandler)){
117 117
             $exceptionHandler = $container->make($exceptionHandler);
118 118
         }
119 119
 
120
-        if ($handleErrors) {
120
+        if ($handleErrors){
121 121
             $exceptionHandler->register();
122 122
         }
123 123
 
124 124
         $container->bind(AttributeResolverRegistryInterface::class, AttributeResolver::class);
125 125
 
126
-        if (!$container->has(InitializerInterface::class)) {
126
+        if (!$container->has(InitializerInterface::class)){
127 127
             $container->bind(InitializerInterface::class, Initializer::class);
128 128
         }
129 129
 
130
-        if (!$container->has(InvokerStrategyInterface::class)) {
130
+        if (!$container->has(InvokerStrategyInterface::class)){
131 131
             $container->bind(InvokerStrategyInterface::class, DefaultInvokerStrategy::class);
132 132
         }
133 133
 
134
-        if ($bootloadManager instanceof Autowire) {
134
+        if ($bootloadManager instanceof Autowire){
135 135
             $bootloadManager = $bootloadManager->resolve($container);
136 136
         }
137 137
         $bootloadManager ??= $container->make(StrategyBasedBootloadManager::class);
138 138
         \assert($bootloadManager instanceof BootloadManagerInterface);
139 139
         $container->bind(BootloadManagerInterface::class, $bootloadManager);
140 140
 
141
-        if (!$container->has(BootloaderRegistryInterface::class)) {
141
+        if (!$container->has(BootloaderRegistryInterface::class)){
142 142
             /** @psalm-suppress InvalidArgument */
143 143
             $container->bindSingleton(BootloaderRegistryInterface::class, [self::class, 'initBootloaderRegistry']);
144 144
         }
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
         $environment ??= new Environment();
168 168
         $this->container->bindSingleton(EnvironmentInterface::class, $environment);
169 169
 
170
-        try {
170
+        try{
171 171
             // will protect any against env overwrite action
172 172
             $this->container->runScope(
173 173
                 [EnvironmentInterface::class => $environment],
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
                     $this->fireCallbacks($this->bootstrappedCallbacks);
185 185
                 },
186 186
             );
187
-        } catch (\Throwable $e) {
187
+        }catch (\Throwable $e){
188 188
             $this->exceptionHandler->handleGlobalException($e);
189 189
 
190 190
             return null;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      */
206 206
     public function running(\Closure ...$callbacks): void
207 207
     {
208
-        foreach ($callbacks as $callback) {
208
+        foreach ($callbacks as $callback){
209 209
             $this->runningCallbacks[] = $callback;
210 210
         }
211 211
     }
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
      */
221 221
     public function booting(\Closure ...$callbacks): void
222 222
     {
223
-        foreach ($callbacks as $callback) {
223
+        foreach ($callbacks as $callback){
224 224
             $this->bootingCallbacks[] = $callback;
225 225
         }
226 226
     }
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      */
236 236
     public function booted(\Closure ...$callbacks): void
237 237
     {
238
-        foreach ($callbacks as $callback) {
238
+        foreach ($callbacks as $callback){
239 239
             $this->bootedCallbacks[] = $callback;
240 240
         }
241 241
     }
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
      */
251 251
     public function bootstrapped(\Closure ...$callbacks): void
252 252
     {
253
-        foreach ($callbacks as $callback) {
253
+        foreach ($callbacks as $callback){
254 254
             $this->bootstrappedCallbacks[] = $callback;
255 255
         }
256 256
     }
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
      * @param class-string<DispatcherInterface>|DispatcherInterface $dispatcher The class name or instance
263 263
      * of the dispatcher. Since v4.0, it will only accept the class name.
264 264
      */
265
-    public function addDispatcher(string|DispatcherInterface $dispatcher): self
265
+    public function addDispatcher(string | DispatcherInterface $dispatcher): self
266 266
     {
267
-        if (\is_object($dispatcher)) {
267
+        if (\is_object($dispatcher)){
268 268
             $dispatcher = $dispatcher::class;
269 269
         }
270 270
 
@@ -286,19 +286,19 @@  discard block
 block discarded – undo
286 286
         $eventDispatcher?->dispatch(new Serving());
287 287
 
288 288
         $serving = $servingScope = null;
289
-        foreach ($this->dispatchers as $dispatcher) {
289
+        foreach ($this->dispatchers as $dispatcher){
290 290
             $reflection = new \ReflectionClass($dispatcher);
291 291
 
292 292
             $scope = ($reflection->getAttributes(DispatcherScope::class)[0] ?? null)?->newInstance()->scope;
293 293
             $this->container->getBinder($scope)->bind($dispatcher, $dispatcher);
294 294
 
295
-            if ($serving === null && $this->canServe($reflection)) {
295
+            if ($serving === null && $this->canServe($reflection)){
296 296
                 $serving = $dispatcher;
297 297
                 $servingScope = $scope;
298 298
             }
299 299
         }
300 300
 
301
-        if ($serving === null) {
301
+        if ($serving === null){
302 302
             $eventDispatcher?->dispatch(new DispatcherNotFound());
303 303
             throw new BootException('Unable to locate active dispatcher.');
304 304
         }
@@ -355,13 +355,13 @@  discard block
 block discarded – undo
355 355
      */
356 356
     protected function fireCallbacks(array &$callbacks): void
357 357
     {
358
-        if ($callbacks === []) {
358
+        if ($callbacks === []){
359 359
             return;
360 360
         }
361 361
 
362
-        do {
362
+        do{
363 363
             $this->container->invoke(\current($callbacks));
364
-        } while (\next($callbacks));
364
+        }while (\next($callbacks));
365 365
 
366 366
         $callbacks = [];
367 367
     }
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
      */
402 402
     private function canServe(\ReflectionClass $reflection): bool
403 403
     {
404
-        if (!$reflection->hasMethod('canServe')) {
404
+        if (!$reflection->hasMethod('canServe')){
405 405
             throw new BootException('Dispatcher must implement static `canServe` method.');
406 406
         }
407 407
 
Please login to merge, or discard this patch.
Braces   +39 added lines, -19 removed lines patch added patch discarded remove patch
@@ -113,32 +113,38 @@  discard block
 block discarded – undo
113 113
     ): static {
114 114
         $exceptionHandler ??= ExceptionHandler::class;
115 115
 
116
-        if (\is_string($exceptionHandler)) {
116
+        if (\is_string($exceptionHandler))
117
+        {
117 118
             $exceptionHandler = $container->make($exceptionHandler);
118 119
         }
119 120
 
120
-        if ($handleErrors) {
121
+        if ($handleErrors)
122
+        {
121 123
             $exceptionHandler->register();
122 124
         }
123 125
 
124 126
         $container->bind(AttributeResolverRegistryInterface::class, AttributeResolver::class);
125 127
 
126
-        if (!$container->has(InitializerInterface::class)) {
128
+        if (!$container->has(InitializerInterface::class))
129
+        {
127 130
             $container->bind(InitializerInterface::class, Initializer::class);
128 131
         }
129 132
 
130
-        if (!$container->has(InvokerStrategyInterface::class)) {
133
+        if (!$container->has(InvokerStrategyInterface::class))
134
+        {
131 135
             $container->bind(InvokerStrategyInterface::class, DefaultInvokerStrategy::class);
132 136
         }
133 137
 
134
-        if ($bootloadManager instanceof Autowire) {
138
+        if ($bootloadManager instanceof Autowire)
139
+        {
135 140
             $bootloadManager = $bootloadManager->resolve($container);
136 141
         }
137 142
         $bootloadManager ??= $container->make(StrategyBasedBootloadManager::class);
138 143
         \assert($bootloadManager instanceof BootloadManagerInterface);
139 144
         $container->bind(BootloadManagerInterface::class, $bootloadManager);
140 145
 
141
-        if (!$container->has(BootloaderRegistryInterface::class)) {
146
+        if (!$container->has(BootloaderRegistryInterface::class))
147
+        {
142 148
             /** @psalm-suppress InvalidArgument */
143 149
             $container->bindSingleton(BootloaderRegistryInterface::class, [self::class, 'initBootloaderRegistry']);
144 150
         }
@@ -167,7 +173,8 @@  discard block
 block discarded – undo
167 173
         $environment ??= new Environment();
168 174
         $this->container->bindSingleton(EnvironmentInterface::class, $environment);
169 175
 
170
-        try {
176
+        try
177
+        {
171 178
             // will protect any against env overwrite action
172 179
             $this->container->runScope(
173 180
                 [EnvironmentInterface::class => $environment],
@@ -184,7 +191,9 @@  discard block
 block discarded – undo
184 191
                     $this->fireCallbacks($this->bootstrappedCallbacks);
185 192
                 },
186 193
             );
187
-        } catch (\Throwable $e) {
194
+        }
195
+        catch (\Throwable $e)
196
+        {
188 197
             $this->exceptionHandler->handleGlobalException($e);
189 198
 
190 199
             return null;
@@ -205,7 +214,8 @@  discard block
 block discarded – undo
205 214
      */
206 215
     public function running(\Closure ...$callbacks): void
207 216
     {
208
-        foreach ($callbacks as $callback) {
217
+        foreach ($callbacks as $callback)
218
+        {
209 219
             $this->runningCallbacks[] = $callback;
210 220
         }
211 221
     }
@@ -220,7 +230,8 @@  discard block
 block discarded – undo
220 230
      */
221 231
     public function booting(\Closure ...$callbacks): void
222 232
     {
223
-        foreach ($callbacks as $callback) {
233
+        foreach ($callbacks as $callback)
234
+        {
224 235
             $this->bootingCallbacks[] = $callback;
225 236
         }
226 237
     }
@@ -235,7 +246,8 @@  discard block
 block discarded – undo
235 246
      */
236 247
     public function booted(\Closure ...$callbacks): void
237 248
     {
238
-        foreach ($callbacks as $callback) {
249
+        foreach ($callbacks as $callback)
250
+        {
239 251
             $this->bootedCallbacks[] = $callback;
240 252
         }
241 253
     }
@@ -250,7 +262,8 @@  discard block
 block discarded – undo
250 262
      */
251 263
     public function bootstrapped(\Closure ...$callbacks): void
252 264
     {
253
-        foreach ($callbacks as $callback) {
265
+        foreach ($callbacks as $callback)
266
+        {
254 267
             $this->bootstrappedCallbacks[] = $callback;
255 268
         }
256 269
     }
@@ -264,7 +277,8 @@  discard block
 block discarded – undo
264 277
      */
265 278
     public function addDispatcher(string|DispatcherInterface $dispatcher): self
266 279
     {
267
-        if (\is_object($dispatcher)) {
280
+        if (\is_object($dispatcher))
281
+        {
268 282
             $dispatcher = $dispatcher::class;
269 283
         }
270 284
 
@@ -286,19 +300,22 @@  discard block
 block discarded – undo
286 300
         $eventDispatcher?->dispatch(new Serving());
287 301
 
288 302
         $serving = $servingScope = null;
289
-        foreach ($this->dispatchers as $dispatcher) {
303
+        foreach ($this->dispatchers as $dispatcher)
304
+        {
290 305
             $reflection = new \ReflectionClass($dispatcher);
291 306
 
292 307
             $scope = ($reflection->getAttributes(DispatcherScope::class)[0] ?? null)?->newInstance()->scope;
293 308
             $this->container->getBinder($scope)->bind($dispatcher, $dispatcher);
294 309
 
295
-            if ($serving === null && $this->canServe($reflection)) {
310
+            if ($serving === null && $this->canServe($reflection))
311
+            {
296 312
                 $serving = $dispatcher;
297 313
                 $servingScope = $scope;
298 314
             }
299 315
         }
300 316
 
301
-        if ($serving === null) {
317
+        if ($serving === null)
318
+        {
302 319
             $eventDispatcher?->dispatch(new DispatcherNotFound());
303 320
             throw new BootException('Unable to locate active dispatcher.');
304 321
         }
@@ -355,11 +372,13 @@  discard block
 block discarded – undo
355 372
      */
356 373
     protected function fireCallbacks(array &$callbacks): void
357 374
     {
358
-        if ($callbacks === []) {
375
+        if ($callbacks === [])
376
+        {
359 377
             return;
360 378
         }
361 379
 
362
-        do {
380
+        do
381
+        {
363 382
             $this->container->invoke(\current($callbacks));
364 383
         } while (\next($callbacks));
365 384
 
@@ -401,7 +420,8 @@  discard block
 block discarded – undo
401 420
      */
402 421
     private function canServe(\ReflectionClass $reflection): bool
403 422
     {
404
-        if (!$reflection->hasMethod('canServe')) {
423
+        if (!$reflection->hasMethod('canServe'))
424
+        {
405 425
             throw new BootException('Dispatcher must implement static `canServe` method.');
406 426
         }
407 427
 
Please login to merge, or discard this patch.