Passed
Push — master ( bbff43...c1ff08 )
by Aleksei
11:50
created
src/Core/tests/Scope/ProxyTest.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
                     // from the current `foo` scope
49 49
                     self::assertInstanceOf(KVLogger::class, $logger);
50 50
 
51
-                    for ($i = 0; $i < 10; $i++) {
51
+                    for ($i = 0; $i < 10; $i++){
52 52
                         // because of proxy
53 53
                         self::assertNotInstanceOf(KVLogger::class, $carrier->getLogger());
54 54
                         self::assertSame('kv', $carrier->logger->getName());
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
                     // from the current `foo` scope
69 69
                     self::assertInstanceOf(FileLogger::class, $logger);
70 70
 
71
-                    for ($i = 0; $i < 10; $i++) {
71
+                    for ($i = 0; $i < 10; $i++){
72 72
                         // because of proxy
73 73
                         self::assertNotInstanceOf(FileLogger::class, $carrier->getLogger());
74 74
                         self::assertSame('file', $carrier->logger->getName());
@@ -85,14 +85,14 @@  discard block
 block discarded – undo
85 85
         $root = new Container();
86 86
         $root->getBinder('http')->bindSingleton(LoggerInterface::class, KVLogger::class);
87 87
 
88
-        $root->runScope(new Scope(), static function (Container $c1) {
88
+        $root->runScope(new Scope(), static function (Container $c1){
89 89
             $c1->runScope(
90 90
                 new Scope(name: 'http'),
91 91
                 static function (
92 92
                     ScopedProxyLoggerCarrier $carrier,
93 93
                     ScopedProxyLoggerCarrier $carrier2,
94 94
                     LoggerInterface $logger,
95
-                ) {
95
+                ){
96 96
                     // from the current `foo` scope
97 97
                     self::assertInstanceOf(KVLogger::class, $logger);
98 98
 
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
         $root = new Container();
113 113
         $root->getBinder('foo')->bind(LoggerInterface::class, KVLogger::class);
114 114
 
115
-        $root->runScope(new Scope(), static function (Container $c1) {
115
+        $root->runScope(new Scope(), static function (Container $c1){
116 116
             $c1->runScope(
117 117
                 new Scope(name: 'foo'),
118
-                static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) {
118
+                static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger){
119 119
                     // from the current `foo` scope
120 120
                     self::assertInstanceOf(KVLogger::class, $logger);
121 121
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
             ->bind(
137 137
                 ContextInterface::class,
138 138
                 new \Spiral\Core\Config\Injectable(
139
-                    new class implements InjectorInterface {
139
+                    new class implements InjectorInterface{
140 140
                         public function createInjection(\ReflectionClass $class, mixed $context = null): Context
141 141
                         {
142 142
                             return new Context($context);
@@ -145,8 +145,8 @@  discard block
 block discarded – undo
145 145
                 ),
146 146
             );
147 147
 
148
-        $root->runScope(new Scope(), static function (Container $c1) {
149
-            $c1->runScope(new Scope(name: 'foo'), static function (Container $c, ContextInterface $param) {
148
+        $root->runScope(new Scope(), static function (Container $c1){
149
+            $c1->runScope(new Scope(name: 'foo'), static function (Container $c, ContextInterface $param){
150 150
                 self::assertInstanceOf(ReflectionParameter::class, $param->value);
151 151
                 self::assertSame('param', $param->value->getName());
152 152
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
             ->bind(
178 178
                 ContextInterface::class,
179 179
                 new \Spiral\Core\Config\Injectable(
180
-                    new class implements InjectorInterface {
180
+                    new class implements InjectorInterface{
181 181
                         public function createInjection(\ReflectionClass $class, mixed $context = null): Context
182 182
                         {
183 183
                             return new Context($context);
@@ -187,15 +187,15 @@  discard block
 block discarded – undo
187 187
             );
188 188
 
189 189
         FiberHelper::runFiberSequence(
190
-            static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx) {
191
-                for ($i = 0; $i < 10; $i++) {
190
+            static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx){
191
+                for ($i = 0; $i < 10; $i++){
192 192
                     self::assertInstanceOf(ReflectionParameter::class, $ctx->getValue(), 'Context injected');
193 193
                     self::assertSame('ctx', $ctx->getValue()->getName());
194 194
                     \Fiber::suspend();
195 195
                 }
196 196
             }),
197
-            static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context) {
198
-                for ($i = 0; $i < 10; $i++) {
197
+            static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context){
198
+                for ($i = 0; $i < 10; $i++){
199 199
                     self::assertInstanceOf(ReflectionParameter::class, $context->getValue(), 'Context injected');
200 200
                     self::assertSame('context', $context->getValue()->getName());
201 201
                     \Fiber::suspend();
@@ -256,10 +256,10 @@  discard block
 block discarded – undo
256 256
     {
257 257
         $root = new Container();
258 258
         $context = (object)['destroyed' => false];
259
-        $class = new class($context) implements DestroyableInterface {
259
+        $class = new class($context) implements DestroyableInterface{
260 260
             public function __construct(
261 261
                 private readonly \stdClass $context,
262
-            ) {
262
+            ){
263 263
             }
264 264
 
265 265
             public function __destruct()
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
             new Scope('http'),
288 288
             static function () use ($root, $proxy) {
289 289
                 self::assertSame('Foo', $proxy->getName());
290
-                $proxy->setName(new class implements \Stringable {
290
+                $proxy->setName(new class implements \Stringable{
291 291
                     public function __toString(): string
292 292
                     {
293 293
                         return 'Bar';
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 
327 327
         $root->runScope(
328 328
             new Scope(),
329
-            static function (#[Proxy] ContainerInterface $proxy, ContainerInterface $scoped) {
329
+            static function (#[Proxy] ContainerInterface $proxy, ContainerInterface $scoped){
330 330
                 self::assertNotSame($scoped, $proxy);
331 331
                 ContainerScope::runScope($proxy, static function (ContainerInterface $passed) use ($proxy, $scoped) {
332 332
                     self::assertNotSame($passed, $proxy);
Please login to merge, or discard this patch.
Braces   +42 added lines, -21 removed lines patch added patch discarded remove patch
@@ -44,11 +44,13 @@  discard block
 block discarded – undo
44 44
                         LoggerInterface::class => KVLogger::class,
45 45
                     ],
46 46
                 ),
47
-                static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use ($lc) {
47
+                static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use ($lc)
48
+                {
48 49
                     // from the current `foo` scope
49 50
                     self::assertInstanceOf(KVLogger::class, $logger);
50 51
 
51
-                    for ($i = 0; $i < 10; $i++) {
52
+                    for ($i = 0; $i < 10; $i++)
53
+                    {
52 54
                         // because of proxy
53 55
                         self::assertNotInstanceOf(KVLogger::class, $carrier->getLogger());
54 56
                         self::assertSame('kv', $carrier->logger->getName());
@@ -64,11 +66,13 @@  discard block
 block discarded – undo
64 66
                         LoggerInterface::class => FileLogger::class,
65 67
                     ],
66 68
                 ),
67
-                static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use ($lc) {
69
+                static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use ($lc)
70
+                {
68 71
                     // from the current `foo` scope
69 72
                     self::assertInstanceOf(FileLogger::class, $logger);
70 73
 
71
-                    for ($i = 0; $i < 10; $i++) {
74
+                    for ($i = 0; $i < 10; $i++)
75
+                    {
72 76
                         // because of proxy
73 77
                         self::assertNotInstanceOf(FileLogger::class, $carrier->getLogger());
74 78
                         self::assertSame('file', $carrier->logger->getName());
@@ -85,7 +89,8 @@  discard block
 block discarded – undo
85 89
         $root = new Container();
86 90
         $root->getBinder('http')->bindSingleton(LoggerInterface::class, KVLogger::class);
87 91
 
88
-        $root->runScope(new Scope(), static function (Container $c1) {
92
+        $root->runScope(new Scope(), static function (Container $c1)
93
+        {
89 94
             $c1->runScope(
90 95
                 new Scope(name: 'http'),
91 96
                 static function (
@@ -112,10 +117,12 @@  discard block
 block discarded – undo
112 117
         $root = new Container();
113 118
         $root->getBinder('foo')->bind(LoggerInterface::class, KVLogger::class);
114 119
 
115
-        $root->runScope(new Scope(), static function (Container $c1) {
120
+        $root->runScope(new Scope(), static function (Container $c1)
121
+        {
116 122
             $c1->runScope(
117 123
                 new Scope(name: 'foo'),
118
-                static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) {
124
+                static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger)
125
+                {
119 126
                     // from the current `foo` scope
120 127
                     self::assertInstanceOf(KVLogger::class, $logger);
121 128
 
@@ -136,7 +143,8 @@  discard block
 block discarded – undo
136 143
             ->bind(
137 144
                 ContextInterface::class,
138 145
                 new \Spiral\Core\Config\Injectable(
139
-                    new class implements InjectorInterface {
146
+                    new class implements InjectorInterface
147
+                    {
140 148
                         public function createInjection(\ReflectionClass $class, mixed $context = null): Context
141 149
                         {
142 150
                             return new Context($context);
@@ -145,8 +153,10 @@  discard block
 block discarded – undo
145 153
                 ),
146 154
             );
147 155
 
148
-        $root->runScope(new Scope(), static function (Container $c1) {
149
-            $c1->runScope(new Scope(name: 'foo'), static function (Container $c, ContextInterface $param) {
156
+        $root->runScope(new Scope(), static function (Container $c1)
157
+        {
158
+            $c1->runScope(new Scope(name: 'foo'), static function (Container $c, ContextInterface $param)
159
+            {
150 160
                 self::assertInstanceOf(ReflectionParameter::class, $param->value);
151 161
                 self::assertSame('param', $param->value->getName());
152 162
 
@@ -177,7 +187,8 @@  discard block
 block discarded – undo
177 187
             ->bind(
178 188
                 ContextInterface::class,
179 189
                 new \Spiral\Core\Config\Injectable(
180
-                    new class implements InjectorInterface {
190
+                    new class implements InjectorInterface
191
+                    {
181 192
                         public function createInjection(\ReflectionClass $class, mixed $context = null): Context
182 193
                         {
183 194
                             return new Context($context);
@@ -187,15 +198,19 @@  discard block
 block discarded – undo
187 198
             );
188 199
 
189 200
         FiberHelper::runFiberSequence(
190
-            static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx) {
191
-                for ($i = 0; $i < 10; $i++) {
201
+            static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx)
202
+            {
203
+                for ($i = 0; $i < 10; $i++)
204
+                {
192 205
                     self::assertInstanceOf(ReflectionParameter::class, $ctx->getValue(), 'Context injected');
193 206
                     self::assertSame('ctx', $ctx->getValue()->getName());
194 207
                     \Fiber::suspend();
195 208
                 }
196 209
             }),
197
-            static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context) {
198
-                for ($i = 0; $i < 10; $i++) {
210
+            static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context)
211
+            {
212
+                for ($i = 0; $i < 10; $i++)
213
+                {
199 214
                     self::assertInstanceOf(ReflectionParameter::class, $context->getValue(), 'Context injected');
200 215
                     self::assertSame('context', $context->getValue()->getName());
201 216
                     \Fiber::suspend();
@@ -211,8 +226,10 @@  discard block
 block discarded – undo
211 226
 
212 227
         $root->runScope(
213 228
             new Scope(),
214
-            static function (#[Proxy] ContainerInterface $cp) use ($root) {
215
-                $root->runScope(new Scope(name: 'http'), static function (ContainerInterface $c) use ($cp) {
229
+            static function (#[Proxy] ContainerInterface $cp) use ($root)
230
+            {
231
+                $root->runScope(new Scope(name: 'http'), static function (ContainerInterface $c) use ($cp)
232
+                {
216 233
                     self::assertNotSame($c, $cp);
217 234
                     self::assertSame($c, $cp->get(ContainerInterface::class));
218 235
                     self::assertInstanceOf(KVLogger::class, $cp->get(LoggerInterface::class));
@@ -256,7 +273,8 @@  discard block
 block discarded – undo
256 273
     {
257 274
         $root = new Container();
258 275
         $context = (object)['destroyed' => false];
259
-        $class = new class($context) implements DestroyableInterface {
276
+        $class = new class($context) implements DestroyableInterface
277
+        {
260 278
             public function __construct(
261 279
                 private readonly \stdClass $context,
262 280
             ) {
@@ -285,7 +303,8 @@  discard block
 block discarded – undo
285 303
 
286 304
         $root->runScope(
287 305
             new Scope('http'),
288
-            static function () use ($root, $proxy) {
306
+            static function () use ($root, $proxy)
307
+            {
289 308
                 self::assertSame('Foo', $proxy->getName());
290 309
                 $proxy->setName(new class implements \Stringable {
291 310
                     public function __toString(): string
@@ -326,9 +345,11 @@  discard block
 block discarded – undo
326 345
 
327 346
         $root->runScope(
328 347
             new Scope(),
329
-            static function (#[Proxy] ContainerInterface $proxy, ContainerInterface $scoped) {
348
+            static function (#[Proxy] ContainerInterface $proxy, ContainerInterface $scoped)
349
+            {
330 350
                 self::assertNotSame($scoped, $proxy);
331
-                ContainerScope::runScope($proxy, static function (ContainerInterface $passed) use ($proxy, $scoped) {
351
+                ContainerScope::runScope($proxy, static function (ContainerInterface $passed) use ($proxy, $scoped)
352
+                {
332 353
                     self::assertNotSame($passed, $proxy);
333 354
                     self::assertSame($scoped, ContainerScope::getContainer());
334 355
                 });
Please login to merge, or discard this patch.
src/Core/src/Internal/Proxy/Resolver.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -19,27 +19,27 @@  discard block
 block discarded – undo
19 19
 {
20 20
     public static function resolve(
21 21
         string $alias,
22
-        \Stringable|string|null $context = null,
22
+        \Stringable | string | null $context = null,
23 23
         ?ContainerInterface $c = null,
24 24
     ): object {
25 25
         $c ??= ContainerScope::getContainer() ?? throw new ContainerException('Proxy is out of scope.');
26 26
 
27
-        try {
27
+        try{
28 28
             /** @psalm-suppress TooManyArguments */
29 29
             $result = $c->get($alias, $context) ?? throw new ContainerException(
30 30
                 'Resolved `null` from the container.',
31 31
             );
32
-        } catch (\Throwable $e) {
32
+        }catch (\Throwable $e){
33 33
             $scope = self::getScope($c);
34 34
             throw new ContainerException(
35 35
                 $scope === null
36 36
                     ? "Unable to resolve `{$alias}` in a Proxy."
37 37
                     : "Unable to resolve `{$alias}` in a Proxy in `{$scope}` scope.",
38
-                previous: $e,
38
+                previous : $e,
39 39
             );
40 40
         }
41 41
 
42
-        if (Proxy::isProxy($result)) {
42
+        if (Proxy::isProxy($result)){
43 43
             $scope = self::getScope($c);
44 44
             throw new RecursiveProxyException(
45 45
                 $scope === null
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
      */
57 57
     private static function getScope(ContainerInterface $c): ?string
58 58
     {
59
-        if (!$c instanceof Container) {
60
-            if (!Proxy::isProxy($c)) {
59
+        if (!$c instanceof Container){
60
+            if (!Proxy::isProxy($c)){
61 61
                 return null;
62 62
             }
63 63
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         }
66 66
 
67 67
         return \implode('.', \array_reverse(\array_map(
68
-            static fn (?string $name): string => $name ?? 'null',
68
+            static fn (?string $name) : string => $name ?? 'null',
69 69
             Introspector::scopeNames($c),
70 70
         )));
71 71
     }
Please login to merge, or discard this patch.
Braces   +11 added lines, -5 removed lines patch added patch discarded remove patch
@@ -24,12 +24,15 @@  discard block
 block discarded – undo
24 24
     ): object {
25 25
         $c ??= ContainerScope::getContainer() ?? throw new ContainerException('Proxy is out of scope.');
26 26
 
27
-        try {
27
+        try
28
+        {
28 29
             /** @psalm-suppress TooManyArguments */
29 30
             $result = $c->get($alias, $context) ?? throw new ContainerException(
30 31
                 'Resolved `null` from the container.',
31 32
             );
32
-        } catch (\Throwable $e) {
33
+        }
34
+        catch (\Throwable $e)
35
+        {
33 36
             $scope = self::getScope($c);
34 37
             throw new ContainerException(
35 38
                 $scope === null
@@ -39,7 +42,8 @@  discard block
 block discarded – undo
39 42
             );
40 43
         }
41 44
 
42
-        if (Proxy::isProxy($result)) {
45
+        if (Proxy::isProxy($result))
46
+        {
43 47
             $scope = self::getScope($c);
44 48
             throw new RecursiveProxyException(
45 49
                 $scope === null
@@ -56,8 +60,10 @@  discard block
 block discarded – undo
56 60
      */
57 61
     private static function getScope(ContainerInterface $c): ?string
58 62
     {
59
-        if (!$c instanceof Container) {
60
-            if (!Proxy::isProxy($c)) {
63
+        if (!$c instanceof Container)
64
+        {
65
+            if (!Proxy::isProxy($c))
66
+            {
61 67
                 return null;
62 68
             }
63 69
 
Please login to merge, or discard this patch.
src/Core/src/ContainerScope.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -34,26 +34,26 @@  discard block
 block discarded – undo
34 34
      */
35 35
     public static function runScope(ContainerInterface $container, callable $scope): mixed
36 36
     {
37
-        if (Proxy::isProxy($container)) {
37
+        if (Proxy::isProxy($container)){
38 38
             // Ignore Proxy to avoid recursion
39 39
             $container = $previous = self::$container ?? throw new ContainerException('Proxy is out of scope.');
40
-        } else {
40
+        }else{
41 41
             [$previous, self::$container] = [self::$container, $container];
42 42
         }
43 43
 
44
-        try {
45
-            if (Fiber::getCurrent() === null) {
44
+        try{
45
+            if (Fiber::getCurrent() === null){
46 46
                 return $scope(self::$container);
47 47
             }
48 48
 
49 49
             // Wrap scope into fiber
50 50
             $fiber = new Fiber(static fn () => $scope(self::$container));
51 51
             $value = $fiber->start();
52
-            while (!$fiber->isTerminated()) {
52
+            while (!$fiber->isTerminated()){
53 53
                 self::$container = $previous;
54
-                try {
54
+                try{
55 55
                     $resume = Fiber::suspend($value);
56
-                } catch (Throwable $e) {
56
+                }catch (Throwable $e){
57 57
                     self::$container = $container;
58 58
                     $value = $fiber->throw($e);
59 59
                     continue;
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
                 $value = $fiber->resume($resume);
64 64
             }
65 65
             return $fiber->getReturn();
66
-        } finally {
66
+        }finally{
67 67
             self::$container = $previous;
68 68
         }
69 69
     }
Please login to merge, or discard this patch.
Braces   +19 added lines, -8 removed lines patch added patch discarded remove patch
@@ -34,26 +34,35 @@  discard block
 block discarded – undo
34 34
      */
35 35
     public static function runScope(ContainerInterface $container, callable $scope): mixed
36 36
     {
37
-        if (Proxy::isProxy($container)) {
37
+        if (Proxy::isProxy($container))
38
+        {
38 39
             // Ignore Proxy to avoid recursion
39 40
             $container = $previous = self::$container ?? throw new ContainerException('Proxy is out of scope.');
40
-        } else {
41
+        }
42
+        else
43
+        {
41 44
             [$previous, self::$container] = [self::$container, $container];
42 45
         }
43 46
 
44
-        try {
45
-            if (Fiber::getCurrent() === null) {
47
+        try
48
+        {
49
+            if (Fiber::getCurrent() === null)
50
+            {
46 51
                 return $scope(self::$container);
47 52
             }
48 53
 
49 54
             // Wrap scope into fiber
50 55
             $fiber = new Fiber(static fn () => $scope(self::$container));
51 56
             $value = $fiber->start();
52
-            while (!$fiber->isTerminated()) {
57
+            while (!$fiber->isTerminated())
58
+            {
53 59
                 self::$container = $previous;
54
-                try {
60
+                try
61
+                {
55 62
                     $resume = Fiber::suspend($value);
56
-                } catch (Throwable $e) {
63
+                }
64
+                catch (Throwable $e)
65
+                {
57 66
                     self::$container = $container;
58 67
                     $value = $fiber->throw($e);
59 68
                     continue;
@@ -63,7 +72,9 @@  discard block
 block discarded – undo
63 72
                 $value = $fiber->resume($resume);
64 73
             }
65 74
             return $fiber->getReturn();
66
-        } finally {
75
+        }
76
+        finally
77
+        {
67 78
             self::$container = $previous;
68 79
         }
69 80
     }
Please login to merge, or discard this patch.