Passed
Pull Request — master (#973)
by Maxim
09:07
created
src/Core/src/Container.php 1 patch
Spacing   +31 added lines, -31 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);
@@ -166,16 +166,16 @@  discard block
 block discarded – undo
166 166
         $binds = &$this->state->bindings;
167 167
         $singletons = &$this->state->singletons;
168 168
         $cleanup = $previous = $prevSin = [];
169
-        foreach ($bindings as $alias => $resolver) {
169
+        foreach ($bindings as $alias => $resolver){
170 170
             // Store previous bindings
171
-            if (isset($binds[$alias])) {
171
+            if (isset($binds[$alias])){
172 172
                 $previous[$alias] = $binds[$alias];
173
-            } else {
173
+            }else{
174 174
                 // Store bindings to be removed
175 175
                 $cleanup[] = $alias;
176 176
             }
177 177
             // Store previous singletons
178
-            if (isset($singletons[$alias])) {
178
+            if (isset($singletons[$alias])){
179 179
                 $prevSin[$alias] = $singletons[$alias];
180 180
                 unset($singletons[$alias]);
181 181
             }
@@ -183,21 +183,21 @@  discard block
 block discarded – undo
183 183
             $this->binder->bind($alias, $resolver);
184 184
         }
185 185
 
186
-        try {
186
+        try{
187 187
             return ContainerScope::getContainer() !== $this
188 188
                 ? ContainerScope::runScope($this, $scope)
189 189
                 : $scope($this);
190
-        } finally {
190
+        }finally{
191 191
             // Remove new bindings
192
-            foreach ($cleanup as $alias) {
192
+            foreach ($cleanup as $alias){
193 193
                 unset($binds[$alias], $singletons[$alias]);
194 194
             }
195 195
             // Restore previous bindings
196
-            foreach ($previous as $alias => $resolver) {
196
+            foreach ($previous as $alias => $resolver){
197 197
                 $binds[$alias] = $resolver;
198 198
             }
199 199
             // Restore singletons
200
-            foreach ($prevSin as $alias => $instance) {
200
+            foreach ($prevSin as $alias => $instance){
201 201
                 $singletons[$alias] = $instance;
202 202
             }
203 203
         }
@@ -211,32 +211,32 @@  discard block
 block discarded – undo
211 211
         // Open scope
212 212
         $container = new self($this->config, $name);
213 213
 
214
-        try {
214
+        try{
215 215
             // Configure scope
216 216
             $container->scope->setParent($this, $this->scope);
217 217
 
218 218
             // Add specific bindings
219
-            foreach ($bindings as $alias => $resolver) {
219
+            foreach ($bindings as $alias => $resolver){
220 220
                 $container->binder->bind($alias, $resolver);
221 221
             }
222 222
 
223 223
             return ContainerScope::runScope(
224 224
                 $container,
225 225
                 static function (self $container) use ($autowire, $closure): mixed {
226
-                    try {
226
+                    try{
227 227
                         return $autowire
228 228
                             ? $container->invoke($closure)
229 229
                             : $closure($container);
230
-                    } finally {
230
+                    }finally{
231 231
                         $container->closeScope();
232 232
                     }
233 233
                 }
234 234
             );
235
-        } finally {
235
+        }finally{
236 236
             // Check the container has not been leaked
237 237
             $link = \WeakReference::create($container);
238 238
             unset($container);
239
-            if ($link->get() !== null) {
239
+            if ($link->get() !== null){
240 240
                 throw new ScopeContainerLeakedException($name, $this->scope->getParentScopeNames());
241 241
             }
242 242
         }
@@ -270,9 +270,9 @@  discard block
 block discarded – undo
270 270
      * @param bool $force If the value is false, an exception will be thrown when attempting
271 271
      *  to bind an already constructed singleton.
272 272
      */
273
-    public function bindSingleton(string $alias, string|array|callable|object $resolver, bool $force = true): void
273
+    public function bindSingleton(string $alias, string | array | callable | object $resolver, bool $force = true): void
274 274
     {
275
-        if ($force) {
275
+        if ($force){
276 276
             $this->binder->removeBinding($alias);
277 277
         }
278 278
 
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
         ]);
342 342
 
343 343
         // Create container services
344
-        foreach ($container->config as $property => $class) {
345
-            if (\property_exists($container, $property)) {
344
+        foreach ($container->config as $property => $class){
345
+            if (\property_exists($container, $property)){
346 346
                 $container->$property = $constructor->get($property, $class);
347 347
             }
348 348
         }
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
     private function closeScope(): void
357 357
     {
358 358
         /** @psalm-suppress RedundantPropertyInitializationCheck */
359
-        if (!isset($this->scope)) {
359
+        if (!isset($this->scope)){
360 360
             $this->destruct();
361 361
             return;
362 362
         }
@@ -365,10 +365,10 @@  discard block
 block discarded – undo
365 365
 
366 366
         // Run finalizers
367 367
         $errors = [];
368
-        foreach ($this->state->finalizers as $finalizer) {
369
-            try {
368
+        foreach ($this->state->finalizers as $finalizer){
369
+            try{
370 370
                 $this->invoker->invoke($finalizer);
371
-            } catch (\Throwable $e) {
371
+            }catch (\Throwable $e){
372 372
                 $errors[] = $e;
373 373
             }
374 374
         }
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
         $this->destruct();
378 378
 
379 379
         // Throw collected errors
380
-        if ($errors !== []) {
380
+        if ($errors !== []){
381 381
             throw new FinalizersException($scopeName, $errors);
382 382
         }
383 383
     }
Please login to merge, or discard this patch.