Passed
Push — master ( d2fe62...2ff31f )
by butschster
08:14
created
src/Core/tests/Scope/FibersTest.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
         self::runInFiber(
32 32
             self::functionScopedTestDataIterator(),
33
-            static function (mixed $suspendValue) {
33
+            static function (mixed $suspendValue){
34 34
                 self::assertNull(ContainerScope::getContainer());
35 35
                 self::assertTrue(\in_array($suspendValue, self::TEST_DATA, true));
36 36
             },
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         );
64 64
 
65 65
         self::assertCount(5, $result);
66
-        foreach ($result as $suspendValue) {
66
+        foreach ($result as $suspendValue){
67 67
             self::assertSame(self::TEST_DATA, $suspendValue);
68 68
         }
69 69
     }
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
         );
82 82
 
83 83
         self::assertCount(2, $result);
84
-        foreach ($result as $suspendValue) {
84
+        foreach ($result as $suspendValue){
85 85
             self::assertSame(self::TEST_DATA, $suspendValue);
86 86
         }
87 87
     }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
         $this->expectExceptionMessage('test');
93 93
 
94 94
         self::runInFiber(
95
-            static function () {
95
+            static function (){
96 96
                 return (new Container())->runScoped(
97 97
                     function (): string {
98 98
                         $result = '';
@@ -114,15 +114,15 @@  discard block
 block discarded – undo
114 114
     public function testCatchThrownException(): void
115 115
     {
116 116
         $result = self::runInFiber(
117
-            static function () {
117
+            static function (){
118 118
                 return (new Container())->runScoped(
119 119
                     function (): string {
120 120
                         $result = '';
121 121
                         $result .= Fiber::suspend('foo');
122 122
                         $result .= Fiber::suspend('bar');
123
-                        try {
123
+                        try{
124 124
                             $result .= Fiber::suspend('error');
125
-                        } catch (\Throwable $e) {
125
+                        }catch (\Throwable $e){
126 126
                             $result .= $e->getMessage();
127 127
                         }
128 128
                         $result .= Fiber::suspend('baz');
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
         ?callable $load = null,
153 153
         ?Container $container = null,
154 154
     ): callable {
155
-        return static function () use ($load, $container): array {
155
+        return static function () use ($load, $container) : array {
156 156
             // The function should be called in a fiber
157 157
             self::assertNotNull(Fiber::getCurrent());
158 158
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
                         $resource = $c3->get('resource');
174 174
                         self::assertInstanceOf(DateTimeImmutable::class, $c3->get('bar'));
175 175
                         self::assertInstanceOf(stdClass::class, $resource);
176
-                        foreach (self::TEST_DATA as $key => $value) {
176
+                        foreach (self::TEST_DATA as $key => $value){
177 177
                             $resource->$key = $value;
178 178
                             $load === null or $load();
179 179
                             Fiber::suspend($value);
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
             }, ['foo' => new DateTime()]);
187 187
             self::assertFalse($c1->has('foo'));
188 188
 
189
-            self::assertSame(self::TEST_DATA, (array) $result);
190
-            return (array) $result;
189
+            self::assertSame(self::TEST_DATA, (array)$result);
190
+            return (array)$result;
191 191
         };
192 192
     }
193 193
 
@@ -204,11 +204,11 @@  discard block
 block discarded – undo
204 204
     {
205 205
         $fiber = new Fiber($callable);
206 206
         $value = $fiber->start();
207
-        while (!$fiber->isTerminated()) {
208
-            if ($check !== null) {
209
-                try {
207
+        while (!$fiber->isTerminated()){
208
+            if ($check !== null){
209
+                try{
210 210
                     $value = $check($value);
211
-                } catch (\Throwable $e) {
211
+                }catch (\Throwable $e){
212 212
                     $value = $fiber->throw($e);
213 213
                     continue;
214 214
                 }
@@ -232,14 +232,14 @@  discard block
 block discarded – undo
232 232
         /** Values that were suspended by the fiber. */
233 233
         $suspends = [];
234 234
         $results = [];
235
-        foreach ($callables as $key => $callable) {
235
+        foreach ($callables as $key => $callable){
236 236
             $fiberGenerators[$key] = (static function () use ($callable) {
237 237
                 $fiber = new Fiber($callable);
238 238
                 // Get ready
239 239
                 yield null;
240 240
 
241 241
                 $value = yield $fiber->start();
242
-                while (!$fiber->isTerminated()) {
242
+                while (!$fiber->isTerminated()){
243 243
                     $value = yield $fiber->resume($value);
244 244
                 }
245 245
                 return $fiber->getReturn();
@@ -249,15 +249,15 @@  discard block
 block discarded – undo
249 249
         }
250 250
 
251 251
 
252
-        while ($fiberGenerators !== []) {
253
-            foreach ($fiberGenerators as $key => $generator) {
254
-                try {
252
+        while ($fiberGenerators !== []){
253
+            foreach ($fiberGenerators as $key => $generator){
254
+                try{
255 255
                     $suspends[$key] = $generator->send($suspends[$key]);
256
-                    if (!$generator->valid()) {
256
+                    if (!$generator->valid()){
257 257
                         $results[$key] = $generator->getReturn();
258 258
                         unset($fiberGenerators[$key]);
259 259
                     }
260
-                } catch (\Throwable $e) {
260
+                }catch (\Throwable $e){
261 261
                     unset($fiberGenerators[$key]);
262 262
                     $results[$key] = $e;
263 263
                 }
Please login to merge, or discard this patch.
src/Core/tests/Scope/SideEffectTest.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
22 22
         $root = new Container();
23 23
         $root->bind(LoggerInterface::class, KVLogger::class);
24 24
 
25
-        $root->runScoped(static function (Container $c1) {
25
+        $root->runScoped(static function (Container $c1){
26 26
             $c1->bind(LoggerInterface::class, FileLogger::class);
27 27
 
28
-            $c1->runScoped(static function (LoggerCarrier $carrier, LoggerInterface $logger) {
28
+            $c1->runScoped(static function (LoggerCarrier $carrier, LoggerInterface $logger){
29 29
                 // from the $root container
30 30
                 self::assertInstanceOf(KVLogger::class, $carrier->logger);
31 31
                 // from the $c1 container
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
         $root = new Container();
40 40
         $root->bind(LoggerInterface::class, KVLogger::class);
41 41
 
42
-        $root->runScoped(static function (Container $c1) {
42
+        $root->runScoped(static function (Container $c1){
43 43
             $c1->bind(LoggerInterface::class, FileLogger::class);
44 44
 
45 45
             self::assertInstanceOf(
Please login to merge, or discard this patch.
src/Core/tests/Scope/FinalizeAttributeTest.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
     {
22 22
         $root = new Container();
23 23
 
24
-        $obj = $root->runScoped(static function (Container $c1) {
25
-            $obj = $c1->runScoped(static function (Container $c2) {
24
+        $obj = $root->runScoped(static function (Container $c1){
25
+            $obj = $c1->runScoped(static function (Container $c2){
26 26
                 $obj = $c2->get(AttrScopeFooFinalize::class);
27 27
 
28 28
                 self::assertFalse($obj->finalized);
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
         self::expectException(FinalizersException::class);
125 125
         self::expectExceptionMessage('An exception has been thrown during finalization of the scope `foo`');
126 126
 
127
-        try {
128
-            $root->runScoped(static function (Container $c1) {
127
+        try{
128
+            $root->runScoped(static function (Container $c1){
129 129
                 $obj = $c1->get(AttrScopeFooFinalize::class);
130 130
                 $obj->throwException = true;
131 131
             }, name: 'foo');
132
-        } catch (FinalizersException $e) {
132
+        }catch (FinalizersException $e){
133 133
             self::assertSame('foo', $e->getScope());
134 134
             self::assertCount(1, $e->getExceptions());
135 135
             // Contains the message from the inner exception.
@@ -153,13 +153,13 @@  discard block
 block discarded – undo
153 153
         self::expectException(FinalizersException::class);
154 154
         self::expectExceptionMessage('3 exceptions have been thrown during finalization of the scope `foo`');
155 155
 
156
-        try {
157
-            $root->runScoped(static function (Container $c1) {
156
+        try{
157
+            $root->runScoped(static function (Container $c1){
158 158
                 $c1->get(AttrScopeFooFinalize::class)->throwException = true;
159 159
                 $c1->get(AttrScopeFooFinalize::class)->throwException = true;
160 160
                 $c1->get(AttrScopeFooFinalize::class)->throwException = true;
161 161
             }, name: 'foo');
162
-        } catch (FinalizersException $e) {
162
+        }catch (FinalizersException $e){
163 163
             self::assertSame('foo', $e->getScope());
164 164
             self::assertCount(3, $e->getExceptions());
165 165
             // Contains the message from the inner exception.
Please login to merge, or discard this patch.
src/Core/tests/Scope/ExceptionsTest.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@  discard block
 block discarded – undo
20 20
 
21 21
         $container = new Container();
22 22
 
23
-        $container->runScoped(static function (Container $c1) {
24
-            try {
23
+        $container->runScoped(static function (Container $c1){
24
+            try{
25 25
                 $c1->get(ExceptionConstructor::class);
26 26
                 self::fail('Exception should be thrown');
27
-            } catch (\Throwable $e) {
27
+            }catch (\Throwable $e){
28 28
                 // self::assertInstanceOf(\InvalidArgumentException::class, $e);
29 29
                 throw $e;
30 30
             }
@@ -38,11 +38,11 @@  discard block
 block discarded – undo
38 38
 
39 39
         $container = new Container();
40 40
 
41
-        $container->runScoped(static function (Container $c1) {
42
-            try {
41
+        $container->runScoped(static function (Container $c1){
42
+            try{
43 43
                 $c1->get(ExceptionConstructor::class);
44 44
                 self::fail('Exception should be thrown');
45
-            } catch (\Throwable $e) {
45
+            }catch (\Throwable $e){
46 46
                 // self::assertInstanceOf(\InvalidArgumentException::class, $e);
47 47
                 throw $e;
48 48
             }
@@ -56,11 +56,11 @@  discard block
 block discarded – undo
56 56
 
57 57
         $container = new Container();
58 58
 
59
-        $container->runScoped(static function (Container $c1) {
60
-            try {
59
+        $container->runScoped(static function (Container $c1){
60
+            try{
61 61
                 $c1->get(DatetimeCarrier::class);
62 62
                 self::fail('Exception should be thrown');
63
-            } catch (\Throwable $e) {
63
+            }catch (\Throwable $e){
64 64
                 self::assertInstanceOf(NotFoundException::class, $e);
65 65
                 self::assertInstanceOf(NotFoundException::class, $e->getPrevious());
66 66
                 self::assertStringContainsString(
Please login to merge, or discard this patch.
src/Core/tests/Scope/UseCaseTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
         $root = new Container();
24 24
         $root->bind('foo', SampleClass::class);
25 25
 
26
-        $root->runScoped(function (ContainerInterface $c1) {
26
+        $root->runScoped(function (ContainerInterface $c1){
27 27
             $c1->get('foo');
28 28
         }, bindings: ['foo' => SampleClass::class]);
29 29
 
Please login to merge, or discard this patch.
src/Core/tests/Scope/ScopeAttributeTest.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     {
34 34
         $root = new Container();
35 35
 
36
-        $root->runScoped(static function (Container $c1) {
36
+        $root->runScoped(static function (Container $c1){
37 37
             $c1->runScoped(static function (Container $c2) use ($c1) {
38 38
                 $obj1 = $c1->get(AttrScopeFooSingleton::class);
39 39
                 $obj2 = $c2->get(AttrScopeFooSingleton::class);
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
         $root = new Container();
57 57
         $root->bind('foo', self::makeFooScopeObject(...));
58 58
 
59
-        $root->runScoped(static function (Container $c1) {
60
-            $c1->runScoped(static function (Container $c2) {
59
+        $root->runScoped(static function (Container $c1){
60
+            $c1->runScoped(static function (Container $c2){
61 61
                 $c2->get('foo');
62 62
             }, name: 'foo');
63 63
         });
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
         $root = new Container();
76 76
         $root->bind('foo', self::makeFooScopeObject(...));
77 77
 
78
-        $root->runScoped(static function (Container $c1) {
79
-            $c1->runScoped(static function (Container $c2) {
78
+        $root->runScoped(static function (Container $c1){
79
+            $c1->runScoped(static function (Container $c2){
80 80
                 $c2->get('foo');
81 81
             });
82 82
         });
@@ -94,15 +94,15 @@  discard block
 block discarded – undo
94 94
 
95 95
         $root = new Container();
96 96
 
97
-        try {
98
-            $root->runScoped(static function (Container $c1) {
99
-                $c1->runScoped(static function (Container $c2) {
100
-                    $c2->runScoped(static function (Container $c3) {
97
+        try{
98
+            $root->runScoped(static function (Container $c1){
99
+                $c1->runScoped(static function (Container $c2){
100
+                    $c2->runScoped(static function (Container $c3){
101 101
                         // do nothing
102 102
                     }, name: 'root');
103 103
                 });
104 104
             });
105
-        } catch (NamedScopeDuplicationException $e) {
105
+        }catch (NamedScopeDuplicationException $e){
106 106
             self::assertSame('root', $e->getScope());
107 107
             throw $e;
108 108
         }
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
     {
118 118
         self::expectException(BadScopeException::class);
119 119
 
120
-        try {
120
+        try{
121 121
             $root = new Container();
122
-            $root->runScoped(static function (Container $c1) {
123
-                $c1->runScoped(static function (Container $c2) {
122
+            $root->runScoped(static function (Container $c1){
123
+                $c1->runScoped(static function (Container $c2){
124 124
                     $c2->get(AttrScopeFoo::class);
125 125
                 });
126 126
             }, name: 'bar');
127
-        } catch (BadScopeException $e) {
127
+        }catch (BadScopeException $e){
128 128
             self::assertSame('foo', $e->getScope());
129 129
             throw $e;
130 130
         }
Please login to merge, or discard this patch.
src/Core/src/Container.php 1 patch
Spacing   +29 added lines, -29 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
     /**
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     public function __construct(
61 61
         private Config $config = new Config(),
62 62
         ?string $scopeName = self::DEFAULT_ROOT_SCOPE_NAME,
63
-    ) {
63
+    ){
64 64
         $this->initServices($this, $scopeName);
65 65
 
66 66
         /** @psalm-suppress RedundantPropertyInitializationCheck */
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
      *
138 138
      * @psalm-suppress InvalidArgument, InvalidCast
139 139
      */
140
-    public function get(string|Autowire $id, string $context = null): mixed
140
+    public function get(string | Autowire $id, string $context = null): mixed
141 141
     {
142 142
         /** @psalm-suppress TooManyArguments */
143 143
         return $this->container->get($id, $context);
@@ -164,26 +164,26 @@  discard block
 block discarded – undo
164 164
     {
165 165
         $binds = &$this->state->bindings;
166 166
         $cleanup = $previous = [];
167
-        foreach ($bindings as $alias => $resolver) {
168
-            if (isset($binds[$alias])) {
167
+        foreach ($bindings as $alias => $resolver){
168
+            if (isset($binds[$alias])){
169 169
                 $previous[$alias] = $binds[$alias];
170
-            } else {
170
+            }else{
171 171
                 $cleanup[] = $alias;
172 172
             }
173 173
 
174 174
             $this->binder->bind($alias, $resolver);
175 175
         }
176 176
 
177
-        try {
177
+        try{
178 178
             return ContainerScope::getContainer() !== $this
179 179
                 ? ContainerScope::runScope($this, $scope)
180 180
                 : $scope($this);
181
-        } finally {
182
-            foreach ($previous as $alias => $resolver) {
181
+        }finally{
182
+            foreach ($previous as $alias => $resolver){
183 183
                 $binds[$alias] = $resolver;
184 184
             }
185 185
 
186
-            foreach ($cleanup as $alias) {
186
+            foreach ($cleanup as $alias){
187 187
                 unset($binds[$alias]);
188 188
             }
189 189
         }
@@ -197,32 +197,32 @@  discard block
 block discarded – undo
197 197
         // Open scope
198 198
         $container = new self($this->config, $name);
199 199
 
200
-        try {
200
+        try{
201 201
             // Configure scope
202 202
             $container->scope->setParent($this, $this->scope);
203 203
 
204 204
             // Add specific bindings
205
-            foreach ($bindings as $alias => $resolver) {
205
+            foreach ($bindings as $alias => $resolver){
206 206
                 $container->binder->bind($alias, $resolver);
207 207
             }
208 208
 
209 209
             return ContainerScope::runScope(
210 210
                 $container,
211 211
                 static function (self $container) use ($autowire, $closure): mixed {
212
-                    try {
212
+                    try{
213 213
                         return $autowire
214 214
                             ? $container->invoke($closure)
215 215
                             : $closure($container);
216
-                    } finally {
216
+                    }finally{
217 217
                         $container->closeScope();
218 218
                     }
219 219
                 }
220 220
             );
221
-        } finally {
221
+        }finally{
222 222
             // Check the container has not been leaked
223 223
             $link = \WeakReference::create($container);
224 224
             unset($container);
225
-            if ($link->get() !== null) {
225
+            if ($link->get() !== null){
226 226
                 throw new ScopeContainerLeakedException($name, $this->scope->getParentScopeNames());
227 227
             }
228 228
         }
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      * for each method call), function array or Closure (executed every call). Only object resolvers
239 239
      * supported by this method.
240 240
      */
241
-    public function bind(string $alias, string|array|callable|object $resolver): void
241
+    public function bind(string $alias, string | array | callable | object $resolver): void
242 242
     {
243 243
         $this->binder->bind($alias, $resolver);
244 244
     }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      *
250 250
      * @psalm-param TResolver $resolver
251 251
      */
252
-    public function bindSingleton(string $alias, string|array|callable|object $resolver): void
252
+    public function bindSingleton(string $alias, string | array | callable | object $resolver): void
253 253
     {
254 254
         $this->binder->bindSingleton($alias, $resolver);
255 255
     }
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
         ]);
320 320
 
321 321
         // Create container services
322
-        foreach ($container->config as $property => $class) {
323
-            if (\property_exists($container, $property)) {
322
+        foreach ($container->config as $property => $class){
323
+            if (\property_exists($container, $property)){
324 324
                 $container->$property = $constructor->get($property, $class);
325 325
             }
326 326
         }
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
     private function closeScope(): void
335 335
     {
336 336
         /** @psalm-suppress RedundantPropertyInitializationCheck */
337
-        if (!isset($this->scope)) {
337
+        if (!isset($this->scope)){
338 338
             $this->destruct();
339 339
             return;
340 340
         }
@@ -343,10 +343,10 @@  discard block
 block discarded – undo
343 343
 
344 344
         // Run finalizers
345 345
         $errors = [];
346
-        foreach ($this->state->finalizers as $finalizer) {
347
-            try {
346
+        foreach ($this->state->finalizers as $finalizer){
347
+            try{
348 348
                 $this->invoker->invoke($finalizer);
349
-            } catch (\Throwable $e) {
349
+            }catch (\Throwable $e){
350 350
                 $errors[] = $e;
351 351
             }
352 352
         }
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
         $this->destruct();
356 356
 
357 357
         // Throw collected errors
358
-        if ($errors !== []) {
358
+        if ($errors !== []){
359 359
             throw new FinalizersException($scopeName, $errors);
360 360
         }
361 361
     }
Please login to merge, or discard this patch.