@@ -28,7 +28,8 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $scope = self::getAccessor($container)->scope; |
| 30 | 30 | $result = []; |
| 31 | - do { |
|
| 31 | + do |
|
| 32 | + { |
|
| 32 | 33 | $result[] = $scope->getScopeName(); |
| 33 | 34 | $scope = $scope->getParentScope(); |
| 34 | 35 | } while ($scope !== null); |
@@ -51,7 +52,8 @@ discard block |
||
| 51 | 52 | |
| 52 | 53 | $container ??= ContainerScope::getContainer(); |
| 53 | 54 | |
| 54 | - if (!$container instanceof Container) { |
|
| 55 | + if (!$container instanceof Container) |
|
| 56 | + { |
|
| 55 | 57 | throw new \RuntimeException('Container is not available.'); |
| 56 | 58 | } |
| 57 | 59 | |
@@ -151,10 +151,13 @@ discard block |
||
| 151 | 151 | { |
| 152 | 152 | $input = clone $this; |
| 153 | 153 | |
| 154 | - if ($add) { |
|
| 154 | + if ($add) |
|
| 155 | + { |
|
| 155 | 156 | $input->prefix .= '.' . $prefix; |
| 156 | 157 | $input->prefix = \trim($input->prefix, '.'); |
| 157 | - } else { |
|
| 158 | + } |
|
| 159 | + else |
|
| 160 | + { |
|
| 158 | 161 | $input->prefix = $prefix; |
| 159 | 162 | } |
| 160 | 163 | |
@@ -190,9 +193,12 @@ discard block |
||
| 190 | 193 | */ |
| 191 | 194 | public function request(): Request |
| 192 | 195 | { |
| 193 | - try { |
|
| 196 | + try |
|
| 197 | + { |
|
| 194 | 198 | $request = $this->container->get(Request::class); |
| 195 | - } catch (ContainerExceptionInterface $e) { |
|
| 199 | + } |
|
| 200 | + catch (ContainerExceptionInterface $e) |
|
| 201 | + { |
|
| 196 | 202 | $scope = implode('.', \array_reverse(Introspector::scopeNames($this->container))); |
| 197 | 203 | throw new ScopeException( |
| 198 | 204 | "Unable to get `ServerRequestInterface` in the `$scope` container scope", |
@@ -202,7 +208,8 @@ discard block |
||
| 202 | 208 | } |
| 203 | 209 | |
| 204 | 210 | // Flushing input state |
| 205 | - if ($this->request !== $request) { |
|
| 211 | + if ($this->request !== $request) |
|
| 212 | + { |
|
| 206 | 213 | $this->bags = []; |
| 207 | 214 | $this->request = $request; |
| 208 | 215 | } |
@@ -219,7 +226,8 @@ discard block |
||
| 219 | 226 | |
| 220 | 227 | $position = \strrpos($header, 'Bearer '); |
| 221 | 228 | |
| 222 | - if ($position !== false) { |
|
| 229 | + if ($position !== false) |
|
| 230 | + { |
|
| 223 | 231 | $header = \substr($header, $position + 7); |
| 224 | 232 | |
| 225 | 233 | return \str_contains($header, ',') |
@@ -273,16 +281,21 @@ discard block |
||
| 273 | 281 | public function isJsonExpected(bool $softMatch = false): bool |
| 274 | 282 | { |
| 275 | 283 | $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept')); |
| 276 | - foreach ($this->jsonTypes as $jsonType) { |
|
| 277 | - if ($acceptHeader->has($jsonType)) { |
|
| 284 | + foreach ($this->jsonTypes as $jsonType) |
|
| 285 | + { |
|
| 286 | + if ($acceptHeader->has($jsonType)) |
|
| 287 | + { |
|
| 278 | 288 | return true; |
| 279 | 289 | } |
| 280 | 290 | } |
| 281 | 291 | |
| 282 | - if ($softMatch) { |
|
| 283 | - foreach ($acceptHeader->getAll() as $item) { |
|
| 292 | + if ($softMatch) |
|
| 293 | + { |
|
| 294 | + foreach ($acceptHeader->getAll() as $item) |
|
| 295 | + { |
|
| 284 | 296 | $itemValue = \strtolower((string) $item->getValue()); |
| 285 | - if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) { |
|
| 297 | + if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) |
|
| 298 | + { |
|
| 286 | 299 | return true; |
| 287 | 300 | } |
| 288 | 301 | } |
@@ -321,19 +334,22 @@ discard block |
||
| 321 | 334 | // ensure proper request association |
| 322 | 335 | $this->request(); |
| 323 | 336 | |
| 324 | - if (isset($this->bags[$name])) { |
|
| 337 | + if (isset($this->bags[$name])) |
|
| 338 | + { |
|
| 325 | 339 | return $this->bags[$name]; |
| 326 | 340 | } |
| 327 | 341 | |
| 328 | 342 | $definition = $this->findBagDefinition($name); |
| 329 | - if (!$definition) { |
|
| 343 | + if (!$definition) |
|
| 344 | + { |
|
| 330 | 345 | throw new InputException(\sprintf("Undefined input bag '%s'", $name)); |
| 331 | 346 | } |
| 332 | 347 | |
| 333 | 348 | $class = $definition['class']; |
| 334 | 349 | $data = \call_user_func([$this->request(), $definition['source']]); |
| 335 | 350 | |
| 336 | - if (!\is_array($data)) { |
|
| 351 | + if (!\is_array($data)) |
|
| 352 | + { |
|
| 337 | 353 | $data = (array)$data; |
| 338 | 354 | } |
| 339 | 355 | |
@@ -342,7 +358,8 @@ discard block |
||
| 342 | 358 | |
| 343 | 359 | public function hasBag(string $name): bool |
| 344 | 360 | { |
| 345 | - if (isset($this->bags[$name])) { |
|
| 361 | + if (isset($this->bags[$name])) |
|
| 362 | + { |
|
| 346 | 363 | return true; |
| 347 | 364 | } |
| 348 | 365 | |
@@ -362,12 +379,15 @@ discard block |
||
| 362 | 379 | */ |
| 363 | 380 | private function findBagDefinition(string $name): ?array |
| 364 | 381 | { |
| 365 | - if (isset($this->bagAssociations[$name])) { |
|
| 382 | + if (isset($this->bagAssociations[$name])) |
|
| 383 | + { |
|
| 366 | 384 | return $this->bagAssociations[$name]; |
| 367 | 385 | } |
| 368 | 386 | |
| 369 | - foreach ($this->bagAssociations as $bag) { |
|
| 370 | - if (isset($bag['alias']) && $bag['alias'] === $name) { |
|
| 387 | + foreach ($this->bagAssociations as $bag) |
|
| 388 | + { |
|
| 389 | + if (isset($bag['alias']) && $bag['alias'] === $name) |
|
| 390 | + { |
|
| 371 | 391 | return $bag; |
| 372 | 392 | } |
| 373 | 393 | } |
@@ -29,11 +29,13 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | protected function getLogger(string $channel = null): LoggerInterface |
| 31 | 31 | { |
| 32 | - if ($channel !== null) { |
|
| 32 | + if ($channel !== null) |
|
| 33 | + { |
|
| 33 | 34 | return $this->allocateLogger($channel); |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | - if ($this->logger !== null) { |
|
| 37 | + if ($this->logger !== null) |
|
| 38 | + { |
|
| 37 | 39 | return $this->logger; |
| 38 | 40 | } |
| 39 | 41 | |
@@ -47,7 +49,8 @@ discard block |
||
| 47 | 49 | private function allocateLogger(string $channel): LoggerInterface |
| 48 | 50 | { |
| 49 | 51 | $container = ContainerScope::getContainer(); |
| 50 | - if ($container === null || !$container->has(LogsInterface::class)) { |
|
| 52 | + if ($container === null || !$container->has(LogsInterface::class)) |
|
| 53 | + { |
|
| 51 | 54 | return $this->logger ?? new NullLogger(); |
| 52 | 55 | } |
| 53 | 56 | |
@@ -35,7 +35,8 @@ discard block |
||
| 35 | 35 | public function testNoScope(): void |
| 36 | 36 | { |
| 37 | 37 | $c = new Container(); |
| 38 | - $c->runScope(new Scope(), function () { |
|
| 38 | + $c->runScope(new Scope(), function () |
|
| 39 | + { |
|
| 39 | 40 | $logger = $this->getLogger(); |
| 40 | 41 | $this->assertInstanceOf(NullLogger::class, $this->getLogger()); |
| 41 | 42 | $this->assertSame($logger, $this->getLogger()); |
@@ -51,7 +52,8 @@ discard block |
||
| 51 | 52 | |
| 52 | 53 | $c->bind(LogsInterface::class, $mock); |
| 53 | 54 | |
| 54 | - $c->runScope(new Scope(), function () { |
|
| 55 | + $c->runScope(new Scope(), function () |
|
| 56 | + { |
|
| 55 | 57 | $logger = $this->getLogger(); |
| 56 | 58 | $this->assertInstanceOf(\Spiral\Logger\NullLogger::class, $this->getLogger()); |
| 57 | 59 | $this->assertSame($logger, $this->getLogger()); |
@@ -73,7 +75,8 @@ discard block |
||
| 73 | 75 | $this->container->bind( |
| 74 | 76 | ConfiguratorInterface::class, |
| 75 | 77 | new ConfigManager( |
| 76 | - new class() implements LoaderInterface { |
|
| 78 | + new class() implements LoaderInterface |
|
| 79 | + { |
|
| 77 | 80 | public function has(string $section): bool |
| 78 | 81 | { |
| 79 | 82 | return false; |
@@ -52,10 +52,13 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $s = $this->getStempler(); |
| 54 | 54 | |
| 55 | - try { |
|
| 55 | + try |
|
| 56 | + { |
|
| 56 | 57 | $s->get('echo', new ViewContext())->render(); |
| 57 | 58 | $this->fail('Exception expected'); |
| 58 | - } catch (RenderException $e) { |
|
| 59 | + } |
|
| 60 | + catch (RenderException $e) |
|
| 61 | + { |
|
| 59 | 62 | $t = $e->getUserTrace()[0]; |
| 60 | 63 | |
| 61 | 64 | $this->assertSame(2, $t['line']); |
@@ -67,10 +70,13 @@ discard block |
||
| 67 | 70 | { |
| 68 | 71 | $s = $this->getStempler(); |
| 69 | 72 | |
| 70 | - try { |
|
| 73 | + try |
|
| 74 | + { |
|
| 71 | 75 | $s->get('other:echo-in', new ViewContext())->render(); |
| 72 | 76 | $this->fail('Exception expected'); |
| 73 | - } catch (RenderException $e) { |
|
| 77 | + } |
|
| 78 | + catch (RenderException $e) |
|
| 79 | + { |
|
| 74 | 80 | $t = $e->getUserTrace(); |
| 75 | 81 | $this->assertCount(2, $t); |
| 76 | 82 | |
@@ -86,9 +92,12 @@ discard block |
||
| 86 | 92 | { |
| 87 | 93 | $twig = $this->getStempler(); |
| 88 | 94 | |
| 89 | - try { |
|
| 95 | + try |
|
| 96 | + { |
|
| 90 | 97 | $twig->get('other:bad', new ViewContext()); |
| 91 | - } catch (CompileException $e) { |
|
| 98 | + } |
|
| 99 | + catch (CompileException $e) |
|
| 100 | + { |
|
| 92 | 101 | $this->assertStringContainsString('bad.dark.php', $e->getFile()); |
| 93 | 102 | } |
| 94 | 103 | } |