Passed
Pull Request — master (#1038)
by Aleksei
11:08
created
src/Core/src/Container.php 2 patches
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
     public const DEFAULT_ROOT_SCOPE_NAME = 'root';
50 50
 
51 51
     private Internal\State $state;
52
-    private ResolverInterface|Internal\Resolver $resolver;
53
-    private FactoryInterface|Internal\Factory $factory;
54
-    private ContainerInterface|Internal\Container $container;
55
-    private BinderInterface|Internal\Binder $binder;
56
-    private InvokerInterface|Internal\Invoker $invoker;
52
+    private ResolverInterface | Internal\Resolver $resolver;
53
+    private FactoryInterface | Internal\Factory $factory;
54
+    private ContainerInterface | Internal\Container $container;
55
+    private BinderInterface | Internal\Binder $binder;
56
+    private InvokerInterface | Internal\Invoker $invoker;
57 57
     private Internal\Scope $scope;
58 58
 
59 59
     /**
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     public function __construct(
63 63
         private Config $config = new Config(),
64 64
         ?string $scopeName = self::DEFAULT_ROOT_SCOPE_NAME,
65
-    ) {
65
+    ){
66 66
         $this->initServices($this, $scopeName);
67 67
 
68 68
         /** @psalm-suppress RedundantPropertyInitializationCheck */
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      * @throws ContainerException
139 139
      * @throws \Throwable
140 140
      */
141
-    public function get(string|Autowire $id, string $context = null): mixed
141
+    public function get(string | Autowire $id, string $context = null): mixed
142 142
     {
143 143
         /** @psalm-suppress TooManyArguments */
144 144
         return $this->container->get($id, $context);
@@ -164,16 +164,16 @@  discard block
 block discarded – undo
164 164
         $binds = &$this->state->bindings;
165 165
         $singletons = &$this->state->singletons;
166 166
         $cleanup = $previous = $prevSin = [];
167
-        foreach ($bindings as $alias => $resolver) {
167
+        foreach ($bindings as $alias => $resolver){
168 168
             // Store previous bindings
169
-            if (isset($binds[$alias])) {
169
+            if (isset($binds[$alias])){
170 170
                 $previous[$alias] = $binds[$alias];
171
-            } else {
171
+            }else{
172 172
                 // Store bindings to be removed
173 173
                 $cleanup[] = $alias;
174 174
             }
175 175
             // Store previous singletons
176
-            if (isset($singletons[$alias])) {
176
+            if (isset($singletons[$alias])){
177 177
                 $prevSin[$alias] = $singletons[$alias];
178 178
                 unset($singletons[$alias]);
179 179
             }
@@ -181,21 +181,21 @@  discard block
 block discarded – undo
181 181
             $this->binder->bind($alias, $resolver);
182 182
         }
183 183
 
184
-        try {
184
+        try{
185 185
             return ContainerScope::getContainer() !== $this
186 186
                 ? ContainerScope::runScope($this, $scope)
187 187
                 : $scope($this);
188
-        } finally {
188
+        }finally{
189 189
             // Remove new bindings
190
-            foreach ($cleanup as $alias) {
190
+            foreach ($cleanup as $alias){
191 191
                 unset($binds[$alias], $singletons[$alias]);
192 192
             }
193 193
             // Restore previous bindings
194
-            foreach ($previous as $alias => $resolver) {
194
+            foreach ($previous as $alias => $resolver){
195 195
                 $binds[$alias] = $resolver;
196 196
             }
197 197
             // Restore singletons
198
-            foreach ($prevSin as $alias => $instance) {
198
+            foreach ($prevSin as $alias => $instance){
199 199
                 $singletons[$alias] = $instance;
200 200
             }
201 201
         }
@@ -213,18 +213,18 @@  discard block
 block discarded – undo
213 213
         $container->scope->setParent($this, $this->scope);
214 214
 
215 215
         // Add specific bindings
216
-        foreach ($bindings as $alias => $resolver) {
216
+        foreach ($bindings as $alias => $resolver){
217 217
             $container->binder->bind($alias, $resolver);
218 218
         }
219 219
 
220 220
         return ContainerScope::runScope(
221 221
             $container,
222 222
             static function (self $container) use ($autowire, $closure): mixed {
223
-                try {
223
+                try{
224 224
                     return $autowire
225 225
                         ? $container->invoke($closure)
226 226
                         : $closure($container);
227
-                } finally {
227
+                }finally{
228 228
                     $container->closeScope();
229 229
                 }
230 230
             }
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
      * @param bool $force If the value is false, an exception will be thrown when attempting
260 260
      *  to bind an already constructed singleton.
261 261
      */
262
-    public function bindSingleton(string $alias, string|array|callable|object $resolver, bool $force = true): void
262
+    public function bindSingleton(string $alias, string | array | callable | object $resolver, bool $force = true): void
263 263
     {
264
-        if ($force) {
264
+        if ($force){
265 265
             $this->binder->removeBinding($alias);
266 266
         }
267 267
 
@@ -330,8 +330,8 @@  discard block
 block discarded – undo
330 330
         ]);
331 331
 
332 332
         // Create container services
333
-        foreach ($container->config as $property => $class) {
334
-            if (\property_exists($container, $property)) {
333
+        foreach ($container->config as $property => $class){
334
+            if (\property_exists($container, $property)){
335 335
                 $container->$property = $constructor->get($property, $class);
336 336
             }
337 337
         }
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
     private function closeScope(): void
346 346
     {
347 347
         /** @psalm-suppress RedundantPropertyInitializationCheck */
348
-        if (!isset($this->scope)) {
348
+        if (!isset($this->scope)){
349 349
             $this->destruct();
350 350
             return;
351 351
         }
@@ -354,10 +354,10 @@  discard block
 block discarded – undo
354 354
 
355 355
         // Run finalizers
356 356
         $errors = [];
357
-        foreach ($this->state->finalizers as $finalizer) {
358
-            try {
357
+        foreach ($this->state->finalizers as $finalizer){
358
+            try{
359 359
                 $this->invoker->invoke($finalizer);
360
-            } catch (\Throwable $e) {
360
+            }catch (\Throwable $e){
361 361
                 $errors[] = $e;
362 362
             }
363 363
         }
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
         $this->destruct();
367 367
 
368 368
         // Throw collected errors
369
-        if ($errors !== []) {
369
+        if ($errors !== []){
370 370
             throw new FinalizersException($scopeName, $errors);
371 371
         }
372 372
     }
Please login to merge, or discard this patch.
Braces   +44 added lines, -20 removed lines patch added patch discarded remove patch
@@ -164,16 +164,21 @@  discard block
 block discarded – undo
164 164
         $binds = &$this->state->bindings;
165 165
         $singletons = &$this->state->singletons;
166 166
         $cleanup = $previous = $prevSin = [];
167
-        foreach ($bindings as $alias => $resolver) {
167
+        foreach ($bindings as $alias => $resolver)
168
+        {
168 169
             // Store previous bindings
169
-            if (isset($binds[$alias])) {
170
+            if (isset($binds[$alias]))
171
+            {
170 172
                 $previous[$alias] = $binds[$alias];
171
-            } else {
173
+            }
174
+            else
175
+            {
172 176
                 // Store bindings to be removed
173 177
                 $cleanup[] = $alias;
174 178
             }
175 179
             // Store previous singletons
176
-            if (isset($singletons[$alias])) {
180
+            if (isset($singletons[$alias]))
181
+            {
177 182
                 $prevSin[$alias] = $singletons[$alias];
178 183
                 unset($singletons[$alias]);
179 184
             }
@@ -181,21 +186,27 @@  discard block
 block discarded – undo
181 186
             $this->binder->bind($alias, $resolver);
182 187
         }
183 188
 
184
-        try {
189
+        try
190
+        {
185 191
             return ContainerScope::getContainer() !== $this
186 192
                 ? ContainerScope::runScope($this, $scope)
187 193
                 : $scope($this);
188
-        } finally {
194
+        }
195
+        finally
196
+        {
189 197
             // Remove new bindings
190
-            foreach ($cleanup as $alias) {
198
+            foreach ($cleanup as $alias)
199
+            {
191 200
                 unset($binds[$alias], $singletons[$alias]);
192 201
             }
193 202
             // Restore previous bindings
194
-            foreach ($previous as $alias => $resolver) {
203
+            foreach ($previous as $alias => $resolver)
204
+            {
195 205
                 $binds[$alias] = $resolver;
196 206
             }
197 207
             // Restore singletons
198
-            foreach ($prevSin as $alias => $instance) {
208
+            foreach ($prevSin as $alias => $instance)
209
+            {
199 210
                 $singletons[$alias] = $instance;
200 211
             }
201 212
         }
@@ -213,18 +224,22 @@  discard block
 block discarded – undo
213 224
         $container->scope->setParent($this, $this->scope);
214 225
 
215 226
         // Add specific bindings
216
-        foreach ($bindings as $alias => $resolver) {
227
+        foreach ($bindings as $alias => $resolver)
228
+        {
217 229
             $container->binder->bind($alias, $resolver);
218 230
         }
219 231
 
220 232
         return ContainerScope::runScope(
221 233
             $container,
222 234
             static function (self $container) use ($autowire, $closure): mixed {
223
-                try {
235
+                try
236
+                {
224 237
                     return $autowire
225 238
                         ? $container->invoke($closure)
226 239
                         : $closure($container);
227
-                } finally {
240
+                }
241
+                finally
242
+                {
228 243
                     $container->closeScope();
229 244
                 }
230 245
             }
@@ -261,7 +276,8 @@  discard block
 block discarded – undo
261 276
      */
262 277
     public function bindSingleton(string $alias, string|array|callable|object $resolver, bool $force = true): void
263 278
     {
264
-        if ($force) {
279
+        if ($force)
280
+        {
265 281
             $this->binder->removeBinding($alias);
266 282
         }
267 283
 
@@ -330,8 +346,10 @@  discard block
 block discarded – undo
330 346
         ]);
331 347
 
332 348
         // Create container services
333
-        foreach ($container->config as $property => $class) {
334
-            if (\property_exists($container, $property)) {
349
+        foreach ($container->config as $property => $class)
350
+        {
351
+            if (\property_exists($container, $property))
352
+            {
335 353
                 $container->$property = $constructor->get($property, $class);
336 354
             }
337 355
         }
@@ -345,7 +363,8 @@  discard block
 block discarded – undo
345 363
     private function closeScope(): void
346 364
     {
347 365
         /** @psalm-suppress RedundantPropertyInitializationCheck */
348
-        if (!isset($this->scope)) {
366
+        if (!isset($this->scope))
367
+        {
349 368
             $this->destruct();
350 369
             return;
351 370
         }
@@ -354,10 +373,14 @@  discard block
 block discarded – undo
354 373
 
355 374
         // Run finalizers
356 375
         $errors = [];
357
-        foreach ($this->state->finalizers as $finalizer) {
358
-            try {
376
+        foreach ($this->state->finalizers as $finalizer)
377
+        {
378
+            try
379
+            {
359 380
                 $this->invoker->invoke($finalizer);
360
-            } catch (\Throwable $e) {
381
+            }
382
+            catch (\Throwable $e)
383
+            {
361 384
                 $errors[] = $e;
362 385
             }
363 386
         }
@@ -366,7 +389,8 @@  discard block
 block discarded – undo
366 389
         $this->destruct();
367 390
 
368 391
         // Throw collected errors
369
-        if ($errors !== []) {
392
+        if ($errors !== [])
393
+        {
370 394
             throw new FinalizersException($scopeName, $errors);
371 395
         }
372 396
     }
Please login to merge, or discard this patch.