@@ -34,19 +34,19 @@ discard block |
||
| 34 | 34 | { |
| 35 | 35 | [$previous, self::$container] = [self::$container, $container]; |
| 36 | 36 | |
| 37 | - try { |
|
| 38 | - if (Fiber::getCurrent() === null) { |
|
| 37 | + try{ |
|
| 38 | + if (Fiber::getCurrent() === null){ |
|
| 39 | 39 | return $scope(self::$container); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // Wrap scope into fiber |
| 43 | 43 | $fiber = new Fiber(static fn () => $scope(self::$container)); |
| 44 | 44 | $value = $fiber->start(); |
| 45 | - while (!$fiber->isTerminated()) { |
|
| 45 | + while (!$fiber->isTerminated()){ |
|
| 46 | 46 | self::$container = $previous; |
| 47 | - try { |
|
| 47 | + try{ |
|
| 48 | 48 | $resume = Fiber::suspend($value); |
| 49 | - } catch (Throwable $e) { |
|
| 49 | + }catch (Throwable $e){ |
|
| 50 | 50 | self::$container = $container; |
| 51 | 51 | $value = $fiber->throw($e); |
| 52 | 52 | continue; |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $value = $fiber->resume($resume); |
| 56 | 56 | } |
| 57 | 57 | return $fiber->getReturn(); |
| 58 | - } finally { |
|
| 58 | + }finally{ |
|
| 59 | 59 | self::$container = $previous; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 92 | 92 | $this->expectExceptionMessage('test'); |
| 93 | 93 | |
| 94 | 94 | self::runInFiber( |
| 95 | - static function () { |
|
| 95 | + static function (){ |
|
| 96 | 96 | return (new Container())->scope( |
| 97 | 97 | function (): string { |
| 98 | 98 | $result = ''; |
@@ -114,15 +114,15 @@ discard block |
||
| 114 | 114 | public function testCatchThrownException(): void |
| 115 | 115 | { |
| 116 | 116 | $result = self::runInFiber( |
| 117 | - static function () { |
|
| 117 | + static function (){ |
|
| 118 | 118 | return (new Container())->scope( |
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |