Passed
Pull Request — master (#840)
by Maxim
07:32
created
src/Boot/src/BootloadManager/Initializer.php 1 patch
Braces   +29 added lines, -14 removed lines patch added patch discarded remove patch
@@ -33,34 +33,42 @@  discard block
 block discarded – undo
33 33
      */
34 34
     public function init(array $classes): \Generator
35 35
     {
36
-        foreach ($classes as $bootloader => $options) {
36
+        foreach ($classes as $bootloader => $options)
37
+        {
37 38
             // default bootload syntax as simple array
38
-            if (\is_string($options) || $options instanceof BootloaderInterface) {
39
+            if (\is_string($options) || $options instanceof BootloaderInterface)
40
+            {
39 41
                 $bootloader = $options;
40 42
                 $options = [];
41 43
             }
42 44
 
43 45
             // Replace class aliases with source classes
44
-            try {
46
+            try
47
+            {
45 48
                 $ref = (new \ReflectionClass($bootloader));
46 49
                 $className = $ref->getName();
47
-            } catch (\ReflectionException) {
50
+            }
51
+            catch (\ReflectionException)
52
+            {
48 53
                 throw new ClassNotFoundException(
49 54
                     \sprintf('Bootloader class `%s` is not exist.', $bootloader)
50 55
                 );
51 56
             }
52 57
 
53
-            if ($this->bootloaders->isBooted($className) || $ref->isAbstract()) {
58
+            if ($this->bootloaders->isBooted($className) || $ref->isAbstract())
59
+            {
54 60
                 continue;
55 61
             }
56 62
 
57 63
             $this->bootloaders->register($className);
58 64
 
59
-            if (!$bootloader instanceof BootloaderInterface) {
65
+            if (!$bootloader instanceof BootloaderInterface)
66
+            {
60 67
                 $bootloader = $this->container->get($bootloader);
61 68
             }
62 69
 
63
-            if (!$this->isBootloader($bootloader)) {
70
+            if (!$this->isBootloader($bootloader))
71
+            {
64 72
                 continue;
65 73
             }
66 74
 
@@ -80,7 +88,8 @@  discard block
 block discarded – undo
80 88
      */
81 89
     protected function initBootloader(BootloaderInterface $bootloader): iterable
82 90
     {
83
-        if ($bootloader instanceof DependedInterface) {
91
+        if ($bootloader instanceof DependedInterface)
92
+        {
84 93
             yield from $this->init($this->getDependencies($bootloader));
85 94
         }
86 95
 
@@ -98,11 +107,13 @@  discard block
 block discarded – undo
98 107
      */
99 108
     protected function initBindings(array $bindings, array $singletons): void
100 109
     {
101
-        foreach ($bindings as $aliases => $resolver) {
110
+        foreach ($bindings as $aliases => $resolver)
111
+        {
102 112
             $this->binder->bind($aliases, $resolver);
103 113
         }
104 114
 
105
-        foreach ($singletons as $aliases => $resolver) {
115
+        foreach ($singletons as $aliases => $resolver)
116
+        {
106 117
             $this->binder->bindSingleton($aliases, $resolver);
107 118
         }
108 119
     }
@@ -115,8 +126,10 @@  discard block
 block discarded – undo
115 126
 
116 127
         $methodsDeps = [];
117 128
 
118
-        foreach (Methods::cases() as $method) {
119
-            if ($reflectionClass->hasMethod($method->value)) {
129
+        foreach (Methods::cases() as $method)
130
+        {
131
+            if ($reflectionClass->hasMethod($method->value))
132
+            {
120 133
                 $methodsDeps[] = $this->findBootloaderClassesInMethod(
121 134
                     $reflectionClass->getMethod($method->value)
122 135
                 );
@@ -129,9 +142,11 @@  discard block
 block discarded – undo
129 142
     protected function findBootloaderClassesInMethod(\ReflectionMethod $method): array
130 143
     {
131 144
         $args = [];
132
-        foreach ($method->getParameters() as $parameter) {
145
+        foreach ($method->getParameters() as $parameter)
146
+        {
133 147
             $type = $parameter->getType();
134
-            if ($type instanceof \ReflectionNamedType && $this->shouldBeBooted($type)) {
148
+            if ($type instanceof \ReflectionNamedType && $this->shouldBeBooted($type))
149
+            {
135 150
                 $args[] = $type->getName();
136 151
             }
137 152
         }
Please login to merge, or discard this patch.
src/Boot/tests/BootloadManager/BootloadersTest.php 1 patch
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,11 +28,13 @@  discard block
 block discarded – undo
28 28
             SampleBootWithMethodBoot::class,
29 29
             SampleBoot::class,
30 30
         ], [
31
-            static function(Container $container, SampleBoot $boot) {
31
+            static function(Container $container, SampleBoot $boot)
32
+            {
32 33
                 $container->bind('efg', $boot);
33 34
             }
34 35
         ], [
35
-            static function(Container $container, SampleBoot $boot) {
36
+            static function(Container $container, SampleBoot $boot)
37
+            {
36 38
                 $container->bind('ghi', $boot);
37 39
             }
38 40
         ]);
@@ -87,7 +89,8 @@  discard block
 block discarded – undo
87 89
         $bootloader = $this->getBootloadManager($container);
88 90
 
89 91
         $bootloader->bootload([
90
-            new class () extends Bootloader {
92
+            new class () extends Bootloader
93
+            {
91 94
                 public const BINDINGS = ['abc' => self::class];
92 95
                 public const SINGLETONS = ['single' => self::class];
93 96
 
Please login to merge, or discard this patch.
src/Boot/src/AbstractKernel.php 1 patch
Braces   +31 added lines, -15 removed lines patch added patch discarded remove patch
@@ -109,22 +109,27 @@  discard block
 block discarded – undo
109 109
     ): static {
110 110
         $exceptionHandler ??= ExceptionHandler::class;
111 111
 
112
-        if (\is_string($exceptionHandler)) {
112
+        if (\is_string($exceptionHandler))
113
+        {
113 114
             $exceptionHandler = $container->make($exceptionHandler);
114 115
         }
115 116
 
116
-        if ($handleErrors) {
117
+        if ($handleErrors)
118
+        {
117 119
             $exceptionHandler->register();
118 120
         }
119 121
 
120
-        if (!$container->has(InitializerInterface::class)) {
122
+        if (!$container->has(InitializerInterface::class))
123
+        {
121 124
             $container->bind(InitializerInterface::class, Initializer::class);
122 125
         }
123
-        if (!$container->has(InvokerStrategyInterface::class)) {
126
+        if (!$container->has(InvokerStrategyInterface::class))
127
+        {
124 128
             $container->bind(InvokerStrategyInterface::class, DefaultInvokerStrategy::class);
125 129
         }
126 130
 
127
-        if ($bootloadManager instanceof Autowire) {
131
+        if ($bootloadManager instanceof Autowire)
132
+        {
128 133
             $bootloadManager = $bootloadManager->resolve($container);
129 134
         }
130 135
         $bootloadManager ??= $container->make(CustomizableBootloadManager::class);
@@ -158,7 +163,8 @@  discard block
 block discarded – undo
158 163
 
159 164
         $this->fireCallbacks($this->runningCallbacks);
160 165
 
161
-        try {
166
+        try
167
+        {
162 168
             // will protect any against env overwrite action
163 169
             $this->container->runScope(
164 170
                 [EnvironmentInterface::class => $environment],
@@ -169,7 +175,9 @@  discard block
 block discarded – undo
169 175
                     $this->fireCallbacks($this->bootstrappedCallbacks);
170 176
                 }
171 177
             );
172
-        } catch (\Throwable $e) {
178
+        }
179
+        catch (\Throwable $e)
180
+        {
173 181
             $this->exceptionHandler->handleGlobalException($e);
174 182
 
175 183
             return null;
@@ -190,7 +198,8 @@  discard block
 block discarded – undo
190 198
      */
191 199
     public function running(Closure ...$callbacks): void
192 200
     {
193
-        foreach ($callbacks as $callback) {
201
+        foreach ($callbacks as $callback)
202
+        {
194 203
             $this->runningCallbacks[] = $callback;
195 204
         }
196 205
     }
@@ -205,7 +214,8 @@  discard block
 block discarded – undo
205 214
      */
206 215
     public function booting(Closure ...$callbacks): void
207 216
     {
208
-        foreach ($callbacks as $callback) {
217
+        foreach ($callbacks as $callback)
218
+        {
209 219
             $this->bootingCallbacks[] = $callback;
210 220
         }
211 221
     }
@@ -220,7 +230,8 @@  discard block
 block discarded – undo
220 230
      */
221 231
     public function booted(Closure ...$callbacks): void
222 232
     {
223
-        foreach ($callbacks as $callback) {
233
+        foreach ($callbacks as $callback)
234
+        {
224 235
             $this->bootedCallbacks[] = $callback;
225 236
         }
226 237
     }
@@ -236,7 +247,8 @@  discard block
 block discarded – undo
236 247
      */
237 248
     public function bootstrapped(Closure ...$callbacks): void
238 249
     {
239
-        foreach ($callbacks as $callback) {
250
+        foreach ($callbacks as $callback)
251
+        {
240 252
             $this->bootstrappedCallbacks[] = $callback;
241 253
         }
242 254
     }
@@ -264,8 +276,10 @@  discard block
 block discarded – undo
264 276
         $eventDispatcher = $this->getEventDispatcher();
265 277
         $eventDispatcher?->dispatch(new Serving());
266 278
 
267
-        foreach ($this->dispatchers as $dispatcher) {
268
-            if ($dispatcher->canServe()) {
279
+        foreach ($this->dispatchers as $dispatcher)
280
+        {
281
+            if ($dispatcher->canServe())
282
+            {
269 283
                 return $this->container->runScope(
270 284
                     [DispatcherInterface::class => $dispatcher],
271 285
                     static function () use ($dispatcher, $eventDispatcher): mixed {
@@ -306,11 +320,13 @@  discard block
 block discarded – undo
306 320
      */
307 321
     protected function fireCallbacks(array &$callbacks): void
308 322
     {
309
-        if ($callbacks === []) {
323
+        if ($callbacks === [])
324
+        {
310 325
             return;
311 326
         }
312 327
 
313
-        do {
328
+        do
329
+        {
314 330
             $this->container->invoke(\current($callbacks));
315 331
         } while (\next($callbacks));
316 332
 
Please login to merge, or discard this patch.