Passed
Pull Request — master (#1065)
by Maxim
23:05
created
src/Core/tests/Scope/UseCaseTest.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
         $root = new Container();
31 31
         $root->bind('foo', SampleClass::class);
32 32
 
33
-        $root->runScoped(function (ContainerInterface $c1) {
33
+        $root->runScoped(function (ContainerInterface $c1){
34 34
             $c1->get('foo');
35 35
         }, bindings: ['foo' => SampleClass::class]);
36 36
 
@@ -297,20 +297,20 @@  discard block
 block discarded – undo
297 297
         $root = new Container();
298 298
         $root->bindSingleton('sampleClass', SampleClass::class);
299 299
 
300
-        $root->runScope(new Scope('foo'), function (Container $container) {
300
+        $root->runScope(new Scope('foo'), function (Container $container){
301 301
             $this->assertTrue($container->has('sampleClass'));
302 302
         });
303 303
 
304
-        $root->runScope(new Scope('foo'), function (Container $container) {
305
-            $container->runScope(new Scope('bar'), function (Container $container) {
304
+        $root->runScope(new Scope('foo'), function (Container $container){
305
+            $container->runScope(new Scope('bar'), function (Container $container){
306 306
                 $this->assertTrue($container->has('sampleClass'));
307 307
             });
308 308
         });
309 309
 
310
-        $root->runScope(new Scope('foo'), function (Container $container) {
310
+        $root->runScope(new Scope('foo'), function (Container $container){
311 311
             $container->bindSingleton('otherClass', SampleClass::class);
312 312
 
313
-            $container->runScope(new Scope('bar'), function (Container $container) {
313
+            $container->runScope(new Scope('bar'), function (Container $container){
314 314
                 $this->assertTrue($container->has('sampleClass'));
315 315
                 $this->assertTrue($container->has('otherClass'));
316 316
             });
@@ -322,33 +322,33 @@  discard block
 block discarded – undo
322 322
         $root = new Container();
323 323
         $root->getBinder('foo')->bindSingleton('sampleClass', AttrScopeFoo::class);
324 324
 
325
-        $root->runScope(new Scope('foo'), function (Container $container) {
325
+        $root->runScope(new Scope('foo'), function (Container $container){
326 326
             $this->assertTrue($container->has('sampleClass'));
327 327
         });
328 328
 
329
-        $root->runScope(new Scope('bar'), function (Container $container) {
329
+        $root->runScope(new Scope('bar'), function (Container $container){
330 330
             $this->assertFalse($container->has('sampleClass'));
331 331
         });
332 332
 
333
-        $root->runScope(new Scope('foo'), function (Container $container) {
334
-            $container->runScope(new Scope('bar'), function (Container $container) {
333
+        $root->runScope(new Scope('foo'), function (Container $container){
334
+            $container->runScope(new Scope('bar'), function (Container $container){
335 335
                 $this->assertTrue($container->has('sampleClass'));
336 336
             });
337 337
         });
338 338
 
339
-        $root->runScope(new Scope('foo'), function (Container $container) {
339
+        $root->runScope(new Scope('foo'), function (Container $container){
340 340
             $container->bindSingleton('otherClass', AttrScopeFoo::class);
341 341
 
342
-            $container->runScope(new Scope('bar'), function (Container $container) {
342
+            $container->runScope(new Scope('bar'), function (Container $container){
343 343
                 $this->assertTrue($container->has('sampleClass'));
344 344
                 $this->assertTrue($container->has('otherClass'));
345 345
             });
346 346
         });
347 347
 
348
-        $root->runScope(new Scope('baz'), function (Container $container) {
348
+        $root->runScope(new Scope('baz'), function (Container $container){
349 349
             $container->getBinder('foo')->bindSingleton('otherClass', AttrScopeFoo::class);
350 350
 
351
-            $container->runScope(new Scope('bar'), function (Container $container) {
351
+            $container->runScope(new Scope('bar'), function (Container $container){
352 352
                 $this->assertFalse($container->has('sampleClass'));
353 353
                 $this->assertFalse($container->has('otherClass'));
354 354
             });
Please login to merge, or discard this patch.
Braces   +44 added lines, -22 removed lines patch added patch discarded remove patch
@@ -30,7 +30,8 @@  discard block
 block discarded – undo
30 30
         $root = new Container();
31 31
         $root->bind('foo', SampleClass::class);
32 32
 
33
-        $root->runScoped(function (ContainerInterface $c1) {
33
+        $root->runScoped(function (ContainerInterface $c1)
34
+        {
34 35
             $c1->get('foo');
35 36
         }, bindings: ['foo' => SampleClass::class]);
36 37
 
@@ -63,7 +64,8 @@  discard block
 block discarded – undo
63 64
     {
64 65
         $root = new Container();
65 66
 
66
-        $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias) {
67
+        $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias)
68
+        {
67 69
             $obj1 = $c1->get($alias);
68 70
             $obj2 = $c1->get($alias);
69 71
 
@@ -88,14 +90,16 @@  discard block
 block discarded – undo
88 90
     {
89 91
         $root = new Container();
90 92
 
91
-        $root->runScoped(function (ContainerInterface $c1) use ($root) {
93
+        $root->runScoped(function (ContainerInterface $c1) use ($root)
94
+        {
92 95
             $obj1 = $c1->get('foo');
93 96
             $this->weakMap->offsetSet($obj1, true);
94 97
 
95 98
             self::assertNotSame($root, $c1);
96 99
             self::assertInstanceOf(stdClass::class, $obj1);
97 100
 
98
-            $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1) {
101
+            $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1)
102
+            {
99 103
                 $obj2 = $c2->get('foo');
100 104
                 $this->weakMap->offsetSet($obj2, true);
101 105
 
@@ -124,14 +128,16 @@  discard block
 block discarded – undo
124 128
         $root->bindSingleton('bar', [Factory::class, 'makeStdClass']);
125 129
         $root->bind(stdClass::class, new stdClass());
126 130
 
127
-        $root->runScoped(function (ContainerInterface $c1) use ($root) {
131
+        $root->runScoped(function (ContainerInterface $c1) use ($root)
132
+        {
128 133
             $obj1 = $c1->get('foo');
129 134
             $this->weakMap->offsetSet($obj1, true);
130 135
 
131 136
             self::assertInstanceOf(stdClass::class, $obj1);
132 137
             // Singleton must be the same
133 138
             self::assertSame($c1->get('bar'), $root->get('bar'));
134
-            $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1) {
139
+            $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1)
140
+            {
135 141
                 $obj2 = $c2->get('foo');
136 142
 
137 143
                 self::assertInstanceOf(stdClass::class, $obj2);
@@ -264,7 +270,8 @@  discard block
 block discarded – undo
264 270
     {
265 271
         $root = new Container();
266 272
 
267
-        $root->invoke(static function () use ($root) {
273
+        $root->invoke(static function () use ($root)
274
+        {
268 275
             self::assertNotNull(\Spiral\Core\ContainerScope::getContainer());
269 276
             self::assertSame($root, \Spiral\Core\ContainerScope::getContainer());
270 277
         });
@@ -273,7 +280,8 @@  discard block
 block discarded – undo
273 280
     public function testRegisterContainerOnGet(): void
274 281
     {
275 282
         $root = new Container();
276
-        $root->bind('foo', function () use ($root) {
283
+        $root->bind('foo', function () use ($root)
284
+        {
277 285
             self::assertNotNull(\Spiral\Core\ContainerScope::getContainer());
278 286
             self::assertSame($root, \Spiral\Core\ContainerScope::getContainer());
279 287
         });
@@ -284,7 +292,8 @@  discard block
 block discarded – undo
284 292
     public function testRegisterContainerOnMake(): void
285 293
     {
286 294
         $root = new Container();
287
-        $root->bind('foo', function () use ($root) {
295
+        $root->bind('foo', function () use ($root)
296
+        {
288 297
             self::assertNotNull(\Spiral\Core\ContainerScope::getContainer());
289 298
             self::assertSame($root, \Spiral\Core\ContainerScope::getContainer());
290 299
         });
@@ -297,20 +306,25 @@  discard block
 block discarded – undo
297 306
         $root = new Container();
298 307
         $root->bindSingleton('sampleClass', SampleClass::class);
299 308
 
300
-        $root->runScope(new Scope('foo'), function (Container $container) {
309
+        $root->runScope(new Scope('foo'), function (Container $container)
310
+        {
301 311
             $this->assertTrue($container->has('sampleClass'));
302 312
         });
303 313
 
304
-        $root->runScope(new Scope('foo'), function (Container $container) {
305
-            $container->runScope(new Scope('bar'), function (Container $container) {
314
+        $root->runScope(new Scope('foo'), function (Container $container)
315
+        {
316
+            $container->runScope(new Scope('bar'), function (Container $container)
317
+            {
306 318
                 $this->assertTrue($container->has('sampleClass'));
307 319
             });
308 320
         });
309 321
 
310
-        $root->runScope(new Scope('foo'), function (Container $container) {
322
+        $root->runScope(new Scope('foo'), function (Container $container)
323
+        {
311 324
             $container->bindSingleton('otherClass', SampleClass::class);
312 325
 
313
-            $container->runScope(new Scope('bar'), function (Container $container) {
326
+            $container->runScope(new Scope('bar'), function (Container $container)
327
+            {
314 328
                 $this->assertTrue($container->has('sampleClass'));
315 329
                 $this->assertTrue($container->has('otherClass'));
316 330
             });
@@ -322,33 +336,41 @@  discard block
 block discarded – undo
322 336
         $root = new Container();
323 337
         $root->getBinder('foo')->bindSingleton('sampleClass', AttrScopeFoo::class);
324 338
 
325
-        $root->runScope(new Scope('foo'), function (Container $container) {
339
+        $root->runScope(new Scope('foo'), function (Container $container)
340
+        {
326 341
             $this->assertTrue($container->has('sampleClass'));
327 342
         });
328 343
 
329
-        $root->runScope(new Scope('bar'), function (Container $container) {
344
+        $root->runScope(new Scope('bar'), function (Container $container)
345
+        {
330 346
             $this->assertFalse($container->has('sampleClass'));
331 347
         });
332 348
 
333
-        $root->runScope(new Scope('foo'), function (Container $container) {
334
-            $container->runScope(new Scope('bar'), function (Container $container) {
349
+        $root->runScope(new Scope('foo'), function (Container $container)
350
+        {
351
+            $container->runScope(new Scope('bar'), function (Container $container)
352
+            {
335 353
                 $this->assertTrue($container->has('sampleClass'));
336 354
             });
337 355
         });
338 356
 
339
-        $root->runScope(new Scope('foo'), function (Container $container) {
357
+        $root->runScope(new Scope('foo'), function (Container $container)
358
+        {
340 359
             $container->bindSingleton('otherClass', AttrScopeFoo::class);
341 360
 
342
-            $container->runScope(new Scope('bar'), function (Container $container) {
361
+            $container->runScope(new Scope('bar'), function (Container $container)
362
+            {
343 363
                 $this->assertTrue($container->has('sampleClass'));
344 364
                 $this->assertTrue($container->has('otherClass'));
345 365
             });
346 366
         });
347 367
 
348
-        $root->runScope(new Scope('baz'), function (Container $container) {
368
+        $root->runScope(new Scope('baz'), function (Container $container)
369
+        {
349 370
             $container->getBinder('foo')->bindSingleton('otherClass', AttrScopeFoo::class);
350 371
 
351
-            $container->runScope(new Scope('bar'), function (Container $container) {
372
+            $container->runScope(new Scope('bar'), function (Container $container)
373
+            {
352 374
                 $this->assertFalse($container->has('sampleClass'));
353 375
                 $this->assertFalse($container->has('otherClass'));
354 376
             });
Please login to merge, or discard this patch.
src/Core/src/Internal/Container.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     use DestructorTrait;
20 20
 
21 21
     private State $state;
22
-    private FactoryInterface|Factory $factory;
22
+    private FactoryInterface | Factory $factory;
23 23
     private Scope $scope;
24 24
 
25 25
     public function __construct(Registry $constructor)
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
      * @throws ContainerException
50 50
      * @throws \Throwable
51 51
      */
52
-    public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed
52
+    public function get(string | Autowire $id, \Stringable | string | null $context = null): mixed
53 53
     {
54
-        if ($id instanceof Autowire) {
54
+        if ($id instanceof Autowire){
55 55
             return $id->resolve($this->factory);
56 56
         }
57 57
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 
62 62
     public function has(string $id): bool
63 63
     {
64
-        if (\array_key_exists($id, $this->state->bindings) || \array_key_exists($id, $this->state->singletons)) {
64
+        if (\array_key_exists($id, $this->state->bindings) || \array_key_exists($id, $this->state->singletons)){
65 65
             return true;
66 66
         }
67 67
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,8 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed
53 53
     {
54
-        if ($id instanceof Autowire) {
54
+        if ($id instanceof Autowire)
55
+        {
55 56
             return $id->resolve($this->factory);
56 57
         }
57 58
 
@@ -61,7 +62,8 @@  discard block
 block discarded – undo
61 62
 
62 63
     public function has(string $id): bool
63 64
     {
64
-        if (\array_key_exists($id, $this->state->bindings) || \array_key_exists($id, $this->state->singletons)) {
65
+        if (\array_key_exists($id, $this->state->bindings) || \array_key_exists($id, $this->state->singletons))
66
+        {
65 67
             return true;
66 68
         }
67 69
 
Please login to merge, or discard this patch.