@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | public readonly string $binder = Binder::class, |
| 47 | 47 | public readonly string $invoker = Invoker::class, |
| 48 | 48 | public readonly string $tracer = Tracer::class, |
| 49 | - ) { |
|
| 49 | + ){ |
|
| 50 | 50 | $this->scope = Scope::class; |
| 51 | 51 | $this->scopedBindings = new Internal\Config\StateStorage(); |
| 52 | 52 | } |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | public function lockRoot(): bool |
| 67 | 67 | { |
| 68 | - try { |
|
| 68 | + try{ |
|
| 69 | 69 | return $this->rootLocked; |
| 70 | - } finally { |
|
| 70 | + }finally{ |
|
| 71 | 71 | $this->rootLocked = false; |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -65,9 +65,12 @@ |
||
| 65 | 65 | |
| 66 | 66 | public function lockRoot(): bool |
| 67 | 67 | { |
| 68 | - try { |
|
| 68 | + try |
|
| 69 | + { |
|
| 69 | 70 | return $this->rootLocked; |
| 70 | - } finally { |
|
| 71 | + } |
|
| 72 | + finally |
|
| 73 | + { |
|
| 71 | 74 | $this->rootLocked = false; |
| 72 | 75 | } |
| 73 | 76 | } |
@@ -12,6 +12,6 @@ |
||
| 12 | 12 | { |
| 13 | 13 | public function __construct( |
| 14 | 14 | public string $method, |
| 15 | - ) { |
|
| 15 | + ){ |
|
| 16 | 16 | } |
| 17 | 17 | } |
@@ -12,6 +12,6 @@ |
||
| 12 | 12 | { |
| 13 | 13 | public function __construct( |
| 14 | 14 | public string $name, |
| 15 | - ) { |
|
| 15 | + ){ |
|
| 16 | 16 | } |
| 17 | 17 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | public function __construct( |
| 12 | 12 | protected string $scope, |
| 13 | 13 | protected string $className, |
| 14 | - ) { |
|
| 14 | + ){ |
|
| 15 | 15 | parent::__construct( |
| 16 | 16 | \sprintf('Class `%s` can be resolved only in `%s` scope.', $className, $scope), |
| 17 | 17 | ); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | public function __construct( |
| 17 | 17 | protected ?string $scope, |
| 18 | 18 | protected array $exceptions, |
| 19 | - ) { |
|
| 19 | + ){ |
|
| 20 | 20 | $count = \count($exceptions); |
| 21 | 21 | parent::__construct( |
| 22 | 22 | \sprintf( |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | $count === 1 ? 'An exception has been' : "$count exceptions have been", |
| 25 | 25 | $scope === null ? 'an unnamed scope' : "the scope `$scope`", |
| 26 | 26 | \implode("\n\n", \array_map( |
| 27 | - static fn (Exception $e): string => \sprintf( |
|
| 27 | + static fn (Exception $e) : string => \sprintf( |
|
| 28 | 28 | "# %s\n%s", |
| 29 | 29 | $e::class, |
| 30 | 30 | $e->getMessage(), |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | { |
| 11 | 11 | public function __construct( |
| 12 | 12 | protected string $scope, |
| 13 | - ) { |
|
| 13 | + ){ |
|
| 14 | 14 | parent::__construct( |
| 15 | 15 | "Error on a scope allocation with the name `{$scope}`. A scope with the same name already exists." |
| 16 | 16 | ); |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | $root = new Container(); |
| 21 | 21 | $root->bind('foo', SampleClass::class); |
| 22 | 22 | |
| 23 | - $root->scope(function (ContainerInterface $c1) { |
|
| 23 | + $root->scope(function (ContainerInterface $c1){ |
|
| 24 | 24 | $c1->get('foo'); |
| 25 | 25 | }, bindings: ['foo' => SampleClass::class]); |
| 26 | 26 | |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | $root = new Container(); |
| 36 | 36 | $root->bind('foo', SampleClass::class); |
| 37 | 37 | |
| 38 | - try { |
|
| 38 | + try{ |
|
| 39 | 39 | $leak = $root->scope(function (ContainerInterface $c1): callable { |
| 40 | 40 | return fn() => $c1->get('foo'); |
| 41 | 41 | }); |
| 42 | 42 | $leak(); |
| 43 | - } catch (\AssertionError $e) { |
|
| 43 | + }catch (\AssertionError $e){ |
|
| 44 | 44 | // Assertions are enabled |
| 45 | 45 | self::assertStringContainsString("Scope Container shouldn't be leaked", $e->getMessage()); |
| 46 | - }catch (\Error $e) { |
|
| 46 | + }catch (\Error $e){ |
|
| 47 | 47 | // Call to destroyed container |
| 48 | 48 | self::assertStringContainsString('must not be accessed before initialization', $e->getMessage()); |
| 49 | 49 | } |
@@ -20,7 +20,8 @@ discard block |
||
| 20 | 20 | $root = new Container(); |
| 21 | 21 | $root->bind('foo', SampleClass::class); |
| 22 | 22 | |
| 23 | - $root->scope(function (ContainerInterface $c1) { |
|
| 23 | + $root->scope(function (ContainerInterface $c1) |
|
| 24 | + { |
|
| 24 | 25 | $c1->get('foo'); |
| 25 | 26 | }, bindings: ['foo' => SampleClass::class]); |
| 26 | 27 | |
@@ -35,15 +36,20 @@ discard block |
||
| 35 | 36 | $root = new Container(); |
| 36 | 37 | $root->bind('foo', SampleClass::class); |
| 37 | 38 | |
| 38 | - try { |
|
| 39 | + try |
|
| 40 | + { |
|
| 39 | 41 | $leak = $root->scope(function (ContainerInterface $c1): callable { |
| 40 | 42 | return fn() => $c1->get('foo'); |
| 41 | 43 | }); |
| 42 | 44 | $leak(); |
| 43 | - } catch (\AssertionError $e) { |
|
| 45 | + } |
|
| 46 | + catch (\AssertionError $e) |
|
| 47 | + { |
|
| 44 | 48 | // Assertions are enabled |
| 45 | 49 | self::assertStringContainsString("Scope Container shouldn't be leaked", $e->getMessage()); |
| 46 | - }catch (\Error $e) { |
|
| 50 | + } |
|
| 51 | + catch (\Error $e) |
|
| 52 | + { |
|
| 47 | 53 | // Call to destroyed container |
| 48 | 54 | self::assertStringContainsString('must not be accessed before initialization', $e->getMessage()); |
| 49 | 55 | } |
@@ -58,7 +64,8 @@ discard block |
||
| 58 | 64 | { |
| 59 | 65 | $root = new Container(); |
| 60 | 66 | |
| 61 | - $root->scope(function (ContainerInterface $c1) use ($theSame, $alias) { |
|
| 67 | + $root->scope(function (ContainerInterface $c1) use ($theSame, $alias) |
|
| 68 | + { |
|
| 62 | 69 | $obj1 = $c1->get($alias); |
| 63 | 70 | $obj2 = $c1->get($alias); |
| 64 | 71 | |
@@ -82,14 +89,16 @@ discard block |
||
| 82 | 89 | { |
| 83 | 90 | $root = new Container(); |
| 84 | 91 | |
| 85 | - $root->scope(function (ContainerInterface $c1) use ($root) { |
|
| 92 | + $root->scope(function (ContainerInterface $c1) use ($root) |
|
| 93 | + { |
|
| 86 | 94 | $obj1 = $c1->get('foo'); |
| 87 | 95 | $this->weakMap->offsetSet($obj1, true); |
| 88 | 96 | |
| 89 | 97 | self::assertNotSame($root, $c1); |
| 90 | 98 | self::assertInstanceOf(stdClass::class, $obj1); |
| 91 | 99 | |
| 92 | - $c1->scope(function (ContainerInterface $c2) use ($root, $c1, $obj1) { |
|
| 100 | + $c1->scope(function (ContainerInterface $c2) use ($root, $c1, $obj1) |
|
| 101 | + { |
|
| 93 | 102 | $obj2 = $c2->get('foo'); |
| 94 | 103 | $this->weakMap->offsetSet($obj2, true); |
| 95 | 104 | |
@@ -118,14 +127,16 @@ discard block |
||
| 118 | 127 | $root->bindSingleton('bar', [self::class, 'makeStdClass']); |
| 119 | 128 | $root->bind(stdClass::class, new stdClass()); |
| 120 | 129 | |
| 121 | - $root->scope(function (ContainerInterface $c1) use ($root) { |
|
| 130 | + $root->scope(function (ContainerInterface $c1) use ($root) |
|
| 131 | + { |
|
| 122 | 132 | $obj1 = $c1->get('foo'); |
| 123 | 133 | $this->weakMap->offsetSet($obj1, true); |
| 124 | 134 | |
| 125 | 135 | self::assertInstanceOf(stdClass::class, $obj1); |
| 126 | 136 | // Singleton must be the same |
| 127 | 137 | self::assertSame($c1->get('bar'), $root->get('bar')); |
| 128 | - $c1->scope(function (ContainerInterface $c2) use ($root, $obj1) { |
|
| 138 | + $c1->scope(function (ContainerInterface $c2) use ($root, $obj1) |
|
| 139 | + { |
|
| 129 | 140 | $obj2 = $c2->get('foo'); |
| 130 | 141 | |
| 131 | 142 | self::assertInstanceOf(stdClass::class, $obj2); |
@@ -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 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | ?callable $load = null, |
| 99 | 99 | ?Container $container = null, |
| 100 | 100 | ): callable { |
| 101 | - return static function () use ($load, $container): array { |
|
| 101 | + return static function () use ($load, $container) : array { |
|
| 102 | 102 | // The function should be called in a fiber |
| 103 | 103 | self::assertNotNull(Fiber::getCurrent()); |
| 104 | 104 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $resource = $c3->get('resource'); |
| 120 | 120 | self::assertInstanceOf(DateTimeImmutable::class, $c3->get('bar')); |
| 121 | 121 | self::assertInstanceOf(stdClass::class, $resource); |
| 122 | - foreach (self::TEST_DATA as $key => $value) { |
|
| 122 | + foreach (self::TEST_DATA as $key => $value){ |
|
| 123 | 123 | $resource->$key = $value; |
| 124 | 124 | $load === null or $load(); |
| 125 | 125 | Fiber::suspend($value); |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | }, ['foo' => new DateTime()]); |
| 133 | 133 | self::assertFalse($c1->has('foo')); |
| 134 | 134 | |
| 135 | - self::assertSame(self::TEST_DATA, (array) $result); |
|
| 136 | - return (array) $result; |
|
| 135 | + self::assertSame(self::TEST_DATA, (array)$result); |
|
| 136 | + return (array)$result; |
|
| 137 | 137 | }; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -150,8 +150,8 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | $fiber = new Fiber($callable); |
| 152 | 152 | $value = $fiber->start(); |
| 153 | - while (!$fiber->isTerminated()) { |
|
| 154 | - if ($check !== null) { |
|
| 153 | + while (!$fiber->isTerminated()){ |
|
| 154 | + if ($check !== null){ |
|
| 155 | 155 | $check($value); |
| 156 | 156 | } |
| 157 | 157 | $value = $fiber->resume($value); |
@@ -173,14 +173,14 @@ discard block |
||
| 173 | 173 | /** Values that were suspended by the fiber. */ |
| 174 | 174 | $suspends = []; |
| 175 | 175 | $results = []; |
| 176 | - foreach ($callables as $key => $callable) { |
|
| 176 | + foreach ($callables as $key => $callable){ |
|
| 177 | 177 | $fiberGenerators[$key] = (static function () use ($callable) { |
| 178 | 178 | $fiber = new Fiber($callable); |
| 179 | 179 | // Get ready |
| 180 | 180 | yield null; |
| 181 | 181 | |
| 182 | 182 | $value = yield $fiber->start(); |
| 183 | - while (!$fiber->isTerminated()) { |
|
| 183 | + while (!$fiber->isTerminated()){ |
|
| 184 | 184 | $value = yield $fiber->resume($value); |
| 185 | 185 | } |
| 186 | 186 | return $fiber->getReturn(); |
@@ -190,15 +190,15 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | |
| 193 | - while ($fiberGenerators !== []) { |
|
| 194 | - foreach ($fiberGenerators as $key => $generator) { |
|
| 195 | - try { |
|
| 193 | + while ($fiberGenerators !== []){ |
|
| 194 | + foreach ($fiberGenerators as $key => $generator){ |
|
| 195 | + try{ |
|
| 196 | 196 | $suspends[$key] = $generator->send($suspends[$key]); |
| 197 | - if (!$generator->valid()) { |
|
| 197 | + if (!$generator->valid()){ |
|
| 198 | 198 | $results[$key] = $generator->getReturn(); |
| 199 | 199 | unset($fiberGenerators[$key]); |
| 200 | 200 | } |
| 201 | - } catch (\Throwable $e) { |
|
| 201 | + }catch (\Throwable $e){ |
|
| 202 | 202 | unset($fiberGenerators[$key]); |
| 203 | 203 | $results[$key] = $e; |
| 204 | 204 | } |
@@ -30,7 +30,8 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | self::runInFiber( |
| 32 | 32 | self::functionScopedTestDataIterator(), |
| 33 | - static function (mixed $suspendValue) { |
|
| 33 | + static function (mixed $suspendValue) |
|
| 34 | + { |
|
| 34 | 35 | self::assertNull(ContainerScope::getContainer()); |
| 35 | 36 | self::assertTrue(\in_array($suspendValue, self::TEST_DATA, true)); |
| 36 | 37 | }, |
@@ -63,7 +64,8 @@ discard block |
||
| 63 | 64 | ); |
| 64 | 65 | |
| 65 | 66 | self::assertCount(5, $result); |
| 66 | - foreach ($result as $suspendValue) { |
|
| 67 | + foreach ($result as $suspendValue) |
|
| 68 | + { |
|
| 67 | 69 | self::assertSame(self::TEST_DATA, $suspendValue); |
| 68 | 70 | } |
| 69 | 71 | } |
@@ -81,7 +83,8 @@ discard block |
||
| 81 | 83 | ); |
| 82 | 84 | |
| 83 | 85 | self::assertCount(2, $result); |
| 84 | - foreach ($result as $suspendValue) { |
|
| 86 | + foreach ($result as $suspendValue) |
|
| 87 | + { |
|
| 85 | 88 | self::assertSame(self::TEST_DATA, $suspendValue); |
| 86 | 89 | } |
| 87 | 90 | } |
@@ -106,20 +109,23 @@ discard block |
||
| 106 | 109 | $c1 = $container ?? new Container(); |
| 107 | 110 | $c1->bindSingleton('resource', new stdClass()); |
| 108 | 111 | |
| 109 | - $result = $c1->scope(static function (Container $c2) use ($load) { |
|
| 112 | + $result = $c1->scope(static function (Container $c2) use ($load) |
|
| 113 | + { |
|
| 110 | 114 | // check local binding |
| 111 | 115 | self::assertTrue($c2->has('foo')); |
| 112 | 116 | self::assertInstanceOf(DateTime::class, $c2->get('foo')); |
| 113 | 117 | |
| 114 | 118 | return $c2->scope( |
| 115 | - static function (ContainerInterface $c3) use ($load) { |
|
| 119 | + static function (ContainerInterface $c3) use ($load) |
|
| 120 | + { |
|
| 116 | 121 | // check local binding |
| 117 | 122 | self::assertTrue($c3->has('bar')); |
| 118 | 123 | |
| 119 | 124 | $resource = $c3->get('resource'); |
| 120 | 125 | self::assertInstanceOf(DateTimeImmutable::class, $c3->get('bar')); |
| 121 | 126 | self::assertInstanceOf(stdClass::class, $resource); |
| 122 | - foreach (self::TEST_DATA as $key => $value) { |
|
| 127 | + foreach (self::TEST_DATA as $key => $value) |
|
| 128 | + { |
|
| 123 | 129 | $resource->$key = $value; |
| 124 | 130 | $load === null or $load(); |
| 125 | 131 | Fiber::suspend($value); |
@@ -150,8 +156,10 @@ discard block |
||
| 150 | 156 | { |
| 151 | 157 | $fiber = new Fiber($callable); |
| 152 | 158 | $value = $fiber->start(); |
| 153 | - while (!$fiber->isTerminated()) { |
|
| 154 | - if ($check !== null) { |
|
| 159 | + while (!$fiber->isTerminated()) |
|
| 160 | + { |
|
| 161 | + if ($check !== null) |
|
| 162 | + { |
|
| 155 | 163 | $check($value); |
| 156 | 164 | } |
| 157 | 165 | $value = $fiber->resume($value); |
@@ -173,14 +181,17 @@ discard block |
||
| 173 | 181 | /** Values that were suspended by the fiber. */ |
| 174 | 182 | $suspends = []; |
| 175 | 183 | $results = []; |
| 176 | - foreach ($callables as $key => $callable) { |
|
| 177 | - $fiberGenerators[$key] = (static function () use ($callable) { |
|
| 184 | + foreach ($callables as $key => $callable) |
|
| 185 | + { |
|
| 186 | + $fiberGenerators[$key] = (static function () use ($callable) |
|
| 187 | + { |
|
| 178 | 188 | $fiber = new Fiber($callable); |
| 179 | 189 | // Get ready |
| 180 | 190 | yield null; |
| 181 | 191 | |
| 182 | 192 | $value = yield $fiber->start(); |
| 183 | - while (!$fiber->isTerminated()) { |
|
| 193 | + while (!$fiber->isTerminated()) |
|
| 194 | + { |
|
| 184 | 195 | $value = yield $fiber->resume($value); |
| 185 | 196 | } |
| 186 | 197 | return $fiber->getReturn(); |
@@ -190,15 +201,21 @@ discard block |
||
| 190 | 201 | } |
| 191 | 202 | |
| 192 | 203 | |
| 193 | - while ($fiberGenerators !== []) { |
|
| 194 | - foreach ($fiberGenerators as $key => $generator) { |
|
| 195 | - try { |
|
| 204 | + while ($fiberGenerators !== []) |
|
| 205 | + { |
|
| 206 | + foreach ($fiberGenerators as $key => $generator) |
|
| 207 | + { |
|
| 208 | + try |
|
| 209 | + { |
|
| 196 | 210 | $suspends[$key] = $generator->send($suspends[$key]); |
| 197 | - if (!$generator->valid()) { |
|
| 211 | + if (!$generator->valid()) |
|
| 212 | + { |
|
| 198 | 213 | $results[$key] = $generator->getReturn(); |
| 199 | 214 | unset($fiberGenerators[$key]); |
| 200 | 215 | } |
| 201 | - } catch (\Throwable $e) { |
|
| 216 | + } |
|
| 217 | + catch (\Throwable $e) |
|
| 218 | + { |
|
| 202 | 219 | unset($fiberGenerators[$key]); |
| 203 | 220 | $results[$key] = $e; |
| 204 | 221 | } |
@@ -10,6 +10,6 @@ |
||
| 10 | 10 | { |
| 11 | 11 | public function __construct( |
| 12 | 12 | public DateTimeInterface $logger, |
| 13 | - ) { |
|
| 13 | + ){ |
|
| 14 | 14 | } |
| 15 | 15 | } |