Passed
Pull Request — master (#840)
by Maxim
07:32
created
src/Boot/src/BootloadManager/Initializer.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
         protected readonly ContainerInterface $container,
24 24
         protected readonly BinderInterface $binder,
25 25
         protected readonly ClassesRegistry $bootloaders = new ClassesRegistry()
26
-    ) {
26
+    ){
27 27
     }
28 28
 
29 29
     /**
@@ -33,34 +33,34 @@  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
             // default bootload syntax as simple array
38
-            if (\is_string($options) || $options instanceof BootloaderInterface) {
38
+            if (\is_string($options) || $options instanceof BootloaderInterface){
39 39
                 $bootloader = $options;
40 40
                 $options = [];
41 41
             }
42 42
 
43 43
             // Replace class aliases with source classes
44
-            try {
44
+            try{
45 45
                 $ref = (new \ReflectionClass($bootloader));
46 46
                 $className = $ref->getName();
47
-            } catch (\ReflectionException) {
47
+            }catch (\ReflectionException){
48 48
                 throw new ClassNotFoundException(
49 49
                     \sprintf('Bootloader class `%s` is not exist.', $bootloader)
50 50
                 );
51 51
             }
52 52
 
53
-            if ($this->bootloaders->isBooted($className) || $ref->isAbstract()) {
53
+            if ($this->bootloaders->isBooted($className) || $ref->isAbstract()){
54 54
                 continue;
55 55
             }
56 56
 
57 57
             $this->bootloaders->register($className);
58 58
 
59
-            if (!$bootloader instanceof BootloaderInterface) {
59
+            if (!$bootloader instanceof BootloaderInterface){
60 60
                 $bootloader = $this->container->get($bootloader);
61 61
             }
62 62
 
63
-            if (!$this->isBootloader($bootloader)) {
63
+            if (!$this->isBootloader($bootloader)){
64 64
                 continue;
65 65
             }
66 66
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     protected function initBootloader(BootloaderInterface $bootloader): iterable
82 82
     {
83
-        if ($bootloader instanceof DependedInterface) {
83
+        if ($bootloader instanceof DependedInterface){
84 84
             yield from $this->init($this->getDependencies($bootloader));
85 85
         }
86 86
 
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
      */
99 99
     protected function initBindings(array $bindings, array $singletons): void
100 100
     {
101
-        foreach ($bindings as $aliases => $resolver) {
101
+        foreach ($bindings as $aliases => $resolver){
102 102
             $this->binder->bind($aliases, $resolver);
103 103
         }
104 104
 
105
-        foreach ($singletons as $aliases => $resolver) {
105
+        foreach ($singletons as $aliases => $resolver){
106 106
             $this->binder->bindSingleton($aliases, $resolver);
107 107
         }
108 108
     }
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 
116 116
         $methodsDeps = [];
117 117
 
118
-        foreach (Methods::cases() as $method) {
119
-            if ($reflectionClass->hasMethod($method->value)) {
118
+        foreach (Methods::cases() as $method){
119
+            if ($reflectionClass->hasMethod($method->value)){
120 120
                 $methodsDeps[] = $this->findBootloaderClassesInMethod(
121 121
                     $reflectionClass->getMethod($method->value)
122 122
                 );
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
     protected function findBootloaderClassesInMethod(\ReflectionMethod $method): array
130 130
     {
131 131
         $args = [];
132
-        foreach ($method->getParameters() as $parameter) {
132
+        foreach ($method->getParameters() as $parameter){
133 133
             $type = $parameter->getType();
134
-            if ($type instanceof \ReflectionNamedType && $this->shouldBeBooted($type)) {
134
+            if ($type instanceof \ReflectionNamedType && $this->shouldBeBooted($type)){
135 135
                 $args[] = $type->getName();
136 136
             }
137 137
         }
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      * @psalm-pure
154 154
      * @psalm-assert-if-true TClass $class
155 155
      */
156
-    protected function isBootloader(string|object $class): bool
156
+    protected function isBootloader(string | object $class): bool
157 157
     {
158 158
         return \is_subclass_of($class, BootloaderInterface::class);
159 159
     }
Please login to merge, or discard this 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 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@  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
                 $container->bind('efg', $boot);
33 33
             }
34 34
         ], [
35
-            static function(Container $container, SampleBoot $boot) {
35
+            static function (Container $container, SampleBoot $boot){
36 36
                 $container->bind('ghi', $boot);
37 37
             }
38 38
         ]);
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
         $bootloader = $this->getBootloadManager($container);
88 88
 
89 89
         $bootloader->bootload([
90
-            new class () extends Bootloader {
90
+            new class () extends Bootloader{
91 91
                 public const BINDINGS = ['abc' => self::class];
92 92
                 public const SINGLETONS = ['single' => self::class];
93 93
 
Please login to merge, or discard this 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/BootloadManager/CustomizableBootloadManager.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
         private readonly InvokerStrategyInterface $invoker,
13 13
         ScopeInterface $scope,
14 14
         InitializerInterface $initializer
15
-    ) {
15
+    ){
16 16
         parent::__construct($scope, $initializer);
17 17
     }
18 18
 
Please login to merge, or discard this patch.
src/Boot/src/BootloadManager/AbstractBootloadManager.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
     public function __construct(
17 17
         private readonly ScopeInterface $scope,
18 18
         protected readonly InitializerInterface $initializer
19
-    ) {
19
+    ){
20 20
     }
21 21
 
22 22
     public function getClasses(): array
Please login to merge, or discard this patch.
src/Boot/src/AbstractKernel.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
         protected readonly ExceptionHandlerInterface $exceptionHandler,
65 65
         protected readonly BootloadManagerInterface $bootloader,
66 66
         array $directories
67
-    ) {
67
+    ){
68 68
         $container->bindSingleton(ExceptionHandlerInterface::class, $exceptionHandler);
69 69
         $container->bindSingleton(ExceptionRendererInterface::class, $exceptionHandler);
70 70
         $container->bindSingleton(ExceptionReporterInterface::class, $exceptionHandler);
@@ -103,28 +103,28 @@  discard block
 block discarded – undo
103 103
     final public static function create(
104 104
         array $directories,
105 105
         bool $handleErrors = true,
106
-        ExceptionHandlerInterface|string|null $exceptionHandler = null,
106
+        ExceptionHandlerInterface | string | null $exceptionHandler = null,
107 107
         Container $container = new Container(),
108
-        BootloadManagerInterface|Autowire|null $bootloadManager = null
108
+        BootloadManagerInterface | Autowire | null $bootloadManager = null
109 109
     ): static {
110 110
         $exceptionHandler ??= ExceptionHandler::class;
111 111
 
112
-        if (\is_string($exceptionHandler)) {
112
+        if (\is_string($exceptionHandler)){
113 113
             $exceptionHandler = $container->make($exceptionHandler);
114 114
         }
115 115
 
116
-        if ($handleErrors) {
116
+        if ($handleErrors){
117 117
             $exceptionHandler->register();
118 118
         }
119 119
 
120
-        if (!$container->has(InitializerInterface::class)) {
120
+        if (!$container->has(InitializerInterface::class)){
121 121
             $container->bind(InitializerInterface::class, Initializer::class);
122 122
         }
123
-        if (!$container->has(InvokerStrategyInterface::class)) {
123
+        if (!$container->has(InvokerStrategyInterface::class)){
124 124
             $container->bind(InvokerStrategyInterface::class, DefaultInvokerStrategy::class);
125 125
         }
126 126
 
127
-        if ($bootloadManager instanceof Autowire) {
127
+        if ($bootloadManager instanceof Autowire){
128 128
             $bootloadManager = $bootloadManager->resolve($container);
129 129
         }
130 130
         $bootloadManager ??= $container->make(CustomizableBootloadManager::class);
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 
159 159
         $this->fireCallbacks($this->runningCallbacks);
160 160
 
161
-        try {
161
+        try{
162 162
             // will protect any against env overwrite action
163 163
             $this->container->runScope(
164 164
                 [EnvironmentInterface::class => $environment],
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
                     $this->fireCallbacks($this->bootstrappedCallbacks);
170 170
                 }
171 171
             );
172
-        } catch (\Throwable $e) {
172
+        }catch (\Throwable $e){
173 173
             $this->exceptionHandler->handleGlobalException($e);
174 174
 
175 175
             return null;
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
      */
191 191
     public function running(Closure ...$callbacks): void
192 192
     {
193
-        foreach ($callbacks as $callback) {
193
+        foreach ($callbacks as $callback){
194 194
             $this->runningCallbacks[] = $callback;
195 195
         }
196 196
     }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      */
206 206
     public function booting(Closure ...$callbacks): void
207 207
     {
208
-        foreach ($callbacks as $callback) {
208
+        foreach ($callbacks as $callback){
209 209
             $this->bootingCallbacks[] = $callback;
210 210
         }
211 211
     }
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
      */
221 221
     public function booted(Closure ...$callbacks): void
222 222
     {
223
-        foreach ($callbacks as $callback) {
223
+        foreach ($callbacks as $callback){
224 224
             $this->bootedCallbacks[] = $callback;
225 225
         }
226 226
     }
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
      */
237 237
     public function bootstrapped(Closure ...$callbacks): void
238 238
     {
239
-        foreach ($callbacks as $callback) {
239
+        foreach ($callbacks as $callback){
240 240
             $this->bootstrappedCallbacks[] = $callback;
241 241
         }
242 242
     }
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
         $eventDispatcher = $this->getEventDispatcher();
265 265
         $eventDispatcher?->dispatch(new Serving());
266 266
 
267
-        foreach ($this->dispatchers as $dispatcher) {
268
-            if ($dispatcher->canServe()) {
267
+        foreach ($this->dispatchers as $dispatcher){
268
+            if ($dispatcher->canServe()){
269 269
                 return $this->container->runScope(
270 270
                     [DispatcherInterface::class => $dispatcher],
271 271
                     static function () use ($dispatcher, $eventDispatcher): mixed {
@@ -306,13 +306,13 @@  discard block
 block discarded – undo
306 306
      */
307 307
     protected function fireCallbacks(array &$callbacks): void
308 308
     {
309
-        if ($callbacks === []) {
309
+        if ($callbacks === []){
310 310
             return;
311 311
         }
312 312
 
313
-        do {
313
+        do{
314 314
             $this->container->invoke(\current($callbacks));
315
-        } while (\next($callbacks));
315
+        }while (\next($callbacks));
316 316
 
317 317
         $callbacks = [];
318 318
     }
Please login to merge, or discard this 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.
src/Boot/src/BootloadManager/BootloadManager.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
         private readonly ResolverInterface $resolver,
22 22
         InitializerInterface $initializer,
23 23
         ?InvokerStrategyInterface $invokerStrategy = null
24
-    ) {
24
+    ){
25 25
         parent::__construct($scope, $initializer);
26 26
 
27 27
         $this->invokerStrategy = $invokerStrategy ?? new DefaultInvokerStrategy(...$this->resolver->resolveArguments(
Please login to merge, or discard this patch.