Passed
Pull Request — master (#1183)
by Abdul Malik
25:31 queued 15:01
created
src/Core/tests/Scope/ProxyTest.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
                     // from the current `foo` scope
50 50
                     self::assertInstanceOf(KVLogger::class, $logger);
51 51
 
52
-                    for ($i = 0; $i < 10; $i++) {
52
+                    for ($i = 0; $i < 10; $i++){
53 53
                         // because of proxy
54 54
                         self::assertNotInstanceOf(KVLogger::class, $carrier->getLogger());
55 55
                         self::assertSame('kv', $carrier->logger->getName());
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
                     // from the current `foo` scope
70 70
                     self::assertInstanceOf(FileLogger::class, $logger);
71 71
 
72
-                    for ($i = 0; $i < 10; $i++) {
72
+                    for ($i = 0; $i < 10; $i++){
73 73
                         // because of proxy
74 74
                         self::assertNotInstanceOf(FileLogger::class, $carrier->getLogger());
75 75
                         self::assertSame('file', $carrier->logger->getName());
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
             ->bind(
138 138
                 ContextInterface::class,
139 139
                 new \Spiral\Core\Config\Injectable(
140
-                    new class implements InjectorInterface {
140
+                    new class implements InjectorInterface{
141 141
                         public function createInjection(\ReflectionClass $class, mixed $context = null): Context
142 142
                         {
143 143
                             return new Context($context);
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
             ->bind(
179 179
                 ContextInterface::class,
180 180
                 new \Spiral\Core\Config\Injectable(
181
-                    new class implements InjectorInterface {
181
+                    new class implements InjectorInterface{
182 182
                         public function createInjection(\ReflectionClass $class, mixed $context = null): Context
183 183
                         {
184 184
                             return new Context($context);
@@ -189,14 +189,14 @@  discard block
 block discarded – undo
189 189
 
190 190
         FiberHelper::runFiberSequence(
191 191
             static fn(): mixed => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx): void {
192
-                for ($i = 0; $i < 10; $i++) {
192
+                for ($i = 0; $i < 10; $i++){
193 193
                     self::assertInstanceOf(ReflectionParameter::class, $ctx->getValue(), 'Context injected');
194 194
                     self::assertSame('ctx', $ctx->getValue()->getName());
195 195
                     \Fiber::suspend();
196 196
                 }
197 197
             }),
198 198
             static fn(): mixed => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context): void {
199
-                for ($i = 0; $i < 10; $i++) {
199
+                for ($i = 0; $i < 10; $i++){
200 200
                     self::assertInstanceOf(ReflectionParameter::class, $context->getValue(), 'Context injected');
201 201
                     self::assertSame('context', $context->getValue()->getName());
202 202
                     \Fiber::suspend();
@@ -257,10 +257,10 @@  discard block
 block discarded – undo
257 257
     {
258 258
         $root = new Container();
259 259
         $context = (object)['destroyed' => false];
260
-        $class = new class($context) implements DestroyableInterface {
260
+        $class = new class($context) implements DestroyableInterface{
261 261
             public function __construct(
262 262
                 private readonly \stdClass $context,
263
-            ) {
263
+            ){
264 264
             }
265 265
 
266 266
             public function __destruct()
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
             new Scope('http'),
289 289
             static function () use ($root, $proxy): void {
290 290
                 self::assertSame('Foo', $proxy->getName());
291
-                $proxy->setName(new class implements \Stringable {
291
+                $proxy->setName(new class implements \Stringable{
292 292
                     public function __toString(): string
293 293
                     {
294 294
                         return 'Bar';
Please login to merge, or discard this patch.
Braces   +14 added lines, -7 removed lines patch added patch discarded remove patch
@@ -49,7 +49,8 @@  discard block
 block discarded – undo
49 49
                     // from the current `foo` scope
50 50
                     self::assertInstanceOf(KVLogger::class, $logger);
51 51
 
52
-                    for ($i = 0; $i < 10; $i++) {
52
+                    for ($i = 0; $i < 10; $i++)
53
+                    {
53 54
                         // because of proxy
54 55
                         self::assertNotInstanceOf(KVLogger::class, $carrier->getLogger());
55 56
                         self::assertSame('kv', $carrier->logger->getName());
@@ -69,7 +70,8 @@  discard block
 block discarded – undo
69 70
                     // from the current `foo` scope
70 71
                     self::assertInstanceOf(FileLogger::class, $logger);
71 72
 
72
-                    for ($i = 0; $i < 10; $i++) {
73
+                    for ($i = 0; $i < 10; $i++)
74
+                    {
73 75
                         // because of proxy
74 76
                         self::assertNotInstanceOf(FileLogger::class, $carrier->getLogger());
75 77
                         self::assertSame('file', $carrier->logger->getName());
@@ -137,7 +139,8 @@  discard block
 block discarded – undo
137 139
             ->bind(
138 140
                 ContextInterface::class,
139 141
                 new \Spiral\Core\Config\Injectable(
140
-                    new class implements InjectorInterface {
142
+                    new class implements InjectorInterface
143
+                    {
141 144
                         public function createInjection(\ReflectionClass $class, mixed $context = null): Context
142 145
                         {
143 146
                             return new Context($context);
@@ -178,7 +181,8 @@  discard block
 block discarded – undo
178 181
             ->bind(
179 182
                 ContextInterface::class,
180 183
                 new \Spiral\Core\Config\Injectable(
181
-                    new class implements InjectorInterface {
184
+                    new class implements InjectorInterface
185
+                    {
182 186
                         public function createInjection(\ReflectionClass $class, mixed $context = null): Context
183 187
                         {
184 188
                             return new Context($context);
@@ -189,14 +193,16 @@  discard block
 block discarded – undo
189 193
 
190 194
         FiberHelper::runFiberSequence(
191 195
             static fn(): mixed => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx): void {
192
-                for ($i = 0; $i < 10; $i++) {
196
+                for ($i = 0; $i < 10; $i++)
197
+                {
193 198
                     self::assertInstanceOf(ReflectionParameter::class, $ctx->getValue(), 'Context injected');
194 199
                     self::assertSame('ctx', $ctx->getValue()->getName());
195 200
                     \Fiber::suspend();
196 201
                 }
197 202
             }),
198 203
             static fn(): mixed => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context): void {
199
-                for ($i = 0; $i < 10; $i++) {
204
+                for ($i = 0; $i < 10; $i++)
205
+                {
200 206
                     self::assertInstanceOf(ReflectionParameter::class, $context->getValue(), 'Context injected');
201 207
                     self::assertSame('context', $context->getValue()->getName());
202 208
                     \Fiber::suspend();
@@ -257,7 +263,8 @@  discard block
 block discarded – undo
257 263
     {
258 264
         $root = new Container();
259 265
         $context = (object)['destroyed' => false];
260
-        $class = new class($context) implements DestroyableInterface {
266
+        $class = new class($context) implements DestroyableInterface
267
+        {
261 268
             public function __construct(
262 269
                 private readonly \stdClass $context,
263 270
             ) {
Please login to merge, or discard this patch.
src/Core/src/Container.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
     public const DEFAULT_ROOT_SCOPE_NAME = 'root';
48 48
 
49 49
     private Internal\State $state;
50
-    private ResolverInterface|Internal\Resolver $resolver;
51
-    private FactoryInterface|Internal\Factory $factory;
52
-    private ContainerInterface|Internal\Container $container;
53
-    private BinderInterface|Internal\Binder $binder;
54
-    private InvokerInterface|Internal\Invoker $invoker;
50
+    private ResolverInterface | Internal\Resolver $resolver;
51
+    private FactoryInterface | Internal\Factory $factory;
52
+    private ContainerInterface | Internal\Container $container;
53
+    private BinderInterface | Internal\Binder $binder;
54
+    private InvokerInterface | Internal\Invoker $invoker;
55 55
     private Internal\Scope $scope;
56 56
 
57 57
     /**
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function __construct(
61 61
         private Config $config = new Config(),
62
-        string|\BackedEnum|null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME,
62
+        string | \BackedEnum | null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME,
63 63
         private Options $options = new Options(),
64
-    ) {
65
-        if (\is_object($scopeName)) {
66
-            $scopeName = (string) $scopeName->value;
64
+    ){
65
+        if (\is_object($scopeName)){
66
+            $scopeName = (string)$scopeName->value;
67 67
         }
68 68
 
69 69
         $this->initServices($this, $scopeName);
@@ -117,11 +117,11 @@  discard block
 block discarded – undo
117 117
      * @throws \Throwable
118 118
      * @psalm-suppress TooManyArguments
119 119
      */
120
-    public function make(string $alias, array $parameters = [], \Stringable|string|null $context = null): mixed
120
+    public function make(string $alias, array $parameters = [], \Stringable | string | null $context = null): mixed
121 121
     {
122 122
         return ContainerScope::getContainer() === $this
123 123
             ? $this->factory->make($alias, $parameters, $context)
124
-            : ContainerScope::runScope($this, fn (): mixed => $this->factory->make($alias, $parameters, $context));
124
+            : ContainerScope::runScope($this, fn () : mixed => $this->factory->make($alias, $parameters, $context));
125 125
     }
126 126
 
127 127
     /**
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      * @throws \Throwable
144 144
      * @psalm-suppress TooManyArguments
145 145
      */
146
-    public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed
146
+    public function get(string | Autowire $id, \Stringable | string | null $context = null): mixed
147 147
     {
148 148
         return ContainerScope::getContainer() === $this
149 149
             ? $this->container->get($id, $context)
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
      *        If {@see string}, the default binder for the given scope will be returned. Default bindings won't affect
164 164
      *        already created Container instances except the case with the root one.
165 165
      */
166
-    public function getBinder(string|\BackedEnum|null $scope = null): BinderInterface
166
+    public function getBinder(string | \BackedEnum | null $scope = null): BinderInterface
167 167
     {
168
-        $scope = \is_object($scope) ? (string) $scope->value : $scope;
168
+        $scope = \is_object($scope) ? (string)$scope->value : $scope;
169 169
 
170 170
         return $scope === null
171 171
             ? $this->binder
@@ -175,25 +175,25 @@  discard block
 block discarded – undo
175 175
     /**
176 176
      * @throws \Throwable
177 177
      */
178
-    public function runScope(Scope|array $bindings, callable $scope): mixed
178
+    public function runScope(Scope | array $bindings, callable $scope): mixed
179 179
     {
180
-        if (!\is_array($bindings)) {
180
+        if (!\is_array($bindings)){
181 181
             return $this->runIsolatedScope($bindings, $scope);
182 182
         }
183 183
 
184 184
         $binds = &$this->state->bindings;
185 185
         $singletons = &$this->state->singletons;
186 186
         $cleanup = $previous = $prevSin = [];
187
-        foreach ($bindings as $alias => $resolver) {
187
+        foreach ($bindings as $alias => $resolver){
188 188
             // Store previous bindings
189
-            if (isset($binds[$alias])) {
189
+            if (isset($binds[$alias])){
190 190
                 $previous[$alias] = $binds[$alias];
191
-            } else {
191
+            }else{
192 192
                 // Store bindings to be removed
193 193
                 $cleanup[] = $alias;
194 194
             }
195 195
             // Store previous singletons
196
-            if (isset($singletons[$alias])) {
196
+            if (isset($singletons[$alias])){
197 197
                 $prevSin[$alias] = $singletons[$alias];
198 198
                 unset($singletons[$alias]);
199 199
             }
@@ -201,21 +201,21 @@  discard block
 block discarded – undo
201 201
             $this->binder->bind($alias, $resolver);
202 202
         }
203 203
 
204
-        try {
204
+        try{
205 205
             return ContainerScope::getContainer() !== $this
206 206
                 ? ContainerScope::runScope($this, $scope)
207 207
                 : $scope($this);
208
-        } finally {
208
+        }finally{
209 209
             // Remove new bindings
210
-            foreach ($cleanup as $alias) {
210
+            foreach ($cleanup as $alias){
211 211
                 unset($binds[$alias], $singletons[$alias]);
212 212
             }
213 213
             // Restore previous bindings
214
-            foreach ($previous as $alias => $resolver) {
214
+            foreach ($previous as $alias => $resolver){
215 215
                 $binds[$alias] = $resolver;
216 216
             }
217 217
             // Restore singletons
218
-            foreach ($prevSin as $alias => $instance) {
218
+            foreach ($prevSin as $alias => $instance){
219 219
                 $singletons[$alias] = $instance;
220 220
             }
221 221
         }
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
      * @param bool $force If the value is false, an exception will be thrown when attempting
262 262
      *  to bind an already constructed singleton.
263 263
      */
264
-    public function bindSingleton(string $alias, string|array|callable|object $resolver, bool $force = true): void
264
+    public function bindSingleton(string $alias, string | array | callable | object $resolver, bool $force = true): void
265 265
     {
266
-        if ($force) {
266
+        if ($force){
267 267
             $this->binder->removeBinding($alias);
268 268
         }
269 269
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
     {
291 291
         return ContainerScope::getContainer() === $this
292 292
             ? $this->invoker->invoke($target, $parameters)
293
-            : ContainerScope::runScope($this, fn (): mixed => $this->invoker->invoke($target, $parameters));
293
+            : ContainerScope::runScope($this, fn () : mixed => $this->invoker->invoke($target, $parameters));
294 294
     }
295 295
 
296 296
     /**
@@ -334,8 +334,8 @@  discard block
 block discarded – undo
334 334
         ], $this->options);
335 335
 
336 336
         // Create container services
337
-        foreach ($container->config as $property => $class) {
338
-            if (\property_exists($container, $property)) {
337
+        foreach ($container->config as $property => $class){
338
+            if (\property_exists($container, $property)){
339 339
                 $container->$property = $constructor->get($property, $class);
340 340
             }
341 341
         }
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
     private function closeScope(): void
350 350
     {
351 351
         /** @psalm-suppress RedundantPropertyInitializationCheck */
352
-        if (!isset($this->scope)) {
352
+        if (!isset($this->scope)){
353 353
             $this->destruct();
354 354
             return;
355 355
         }
@@ -358,10 +358,10 @@  discard block
 block discarded – undo
358 358
 
359 359
         // Run finalizers
360 360
         $errors = [];
361
-        foreach ($this->state->finalizers as $finalizer) {
362
-            try {
361
+        foreach ($this->state->finalizers as $finalizer){
362
+            try{
363 363
                 $this->invoker->invoke($finalizer);
364
-            } catch (\Throwable $e) {
364
+            }catch (\Throwable $e){
365 365
                 $errors[] = $e;
366 366
             }
367 367
         }
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
         $this->destruct();
371 371
 
372 372
         // Throw collected errors
373
-        if ($errors !== []) {
373
+        if ($errors !== []){
374 374
             throw new FinalizersException($scopeName, $errors);
375 375
         }
376 376
     }
@@ -392,18 +392,18 @@  discard block
 block discarded – undo
392 392
         $container->scope->setParent($this, $this->scope, $this->factory);
393 393
 
394 394
         // Add specific bindings
395
-        foreach ($config->bindings as $alias => $resolver) {
395
+        foreach ($config->bindings as $alias => $resolver){
396 396
             $container->binder->bind($alias, $resolver);
397 397
         }
398 398
 
399 399
         return ContainerScope::runScope(
400 400
             $container,
401 401
             static function (self $container) use ($config, $closure): mixed {
402
-                try {
402
+                try{
403 403
                     return $config->autowire
404 404
                         ? $container->invoke($closure)
405 405
                         : $closure($container);
406
-                } finally {
406
+                }finally{
407 407
                     $container->closeScope();
408 408
                 }
409 409
             }
Please login to merge, or discard this patch.