@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | $this->files = new Files(); |
| 22 | 22 | $this->fileSnapshot = new FileSnapshot( |
| 23 | - __DIR__ . '/snapshots', |
|
| 23 | + __DIR__.'/snapshots', |
|
| 24 | 24 | 1, |
| 25 | 25 | Verbosity::DEBUG, |
| 26 | 26 | new PlainRenderer(), |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | protected function tearDown(): void |
| 32 | 32 | { |
| 33 | - $this->files->deleteDirectory(__DIR__ . '/snapshots'); |
|
| 33 | + $this->files->deleteDirectory(__DIR__.'/snapshots'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | public function testCreate(): void |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $this->assertStringContainsString('message', $s->getMessage()); |
| 45 | 45 | $this->assertStringContainsString(__FILE__, $s->getMessage()); |
| 46 | 46 | $this->assertStringContainsString('38', $s->getMessage()); |
| 47 | - $this->assertCount(1, $this->files->getFiles(__DIR__ . '/snapshots')); |
|
| 47 | + $this->assertCount(1, $this->files->getFiles(__DIR__.'/snapshots')); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | public function testCreateBiggerThanMaxFiles(): void |
@@ -58,6 +58,6 @@ discard block |
||
| 58 | 58 | $this->assertSame($e, $s->getException()); |
| 59 | 59 | $this->assertSame($e2, $s2->getException()); |
| 60 | 60 | |
| 61 | - $this->assertCount(1, $this->files->getFiles(__DIR__ . '/snapshots')); |
|
| 61 | + $this->assertCount(1, $this->files->getFiles(__DIR__.'/snapshots')); |
|
| 62 | 62 | } |
| 63 | 63 | } |
@@ -55,12 +55,17 @@ |
||
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | 57 | $count = 0; |
| 58 | - foreach ($finder as $file) { |
|
| 58 | + foreach ($finder as $file) |
|
| 59 | + { |
|
| 59 | 60 | $count++; |
| 60 | - if ($count > $this->maxFiles) { |
|
| 61 | - try { |
|
| 61 | + if ($count > $this->maxFiles) |
|
| 62 | + { |
|
| 63 | + try |
|
| 64 | + { |
|
| 62 | 65 | $this->files->delete($file->getRealPath()); |
| 63 | - } catch (FilesException) { |
|
| 66 | + } |
|
| 67 | + catch (FilesException) |
|
| 68 | + { |
|
| 64 | 69 | // ignore |
| 65 | 70 | } |
| 66 | 71 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | private readonly Verbosity $verbosity, |
| 20 | 20 | private readonly ExceptionRendererInterface $renderer, |
| 21 | 21 | private readonly FilesInterface $files |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function create(\Throwable $e): SnapshotInterface |
@@ -51,16 +51,16 @@ discard block |
||
| 51 | 51 | { |
| 52 | 52 | $finder = new Finder(); |
| 53 | 53 | $finder->in($this->directory)->sort( |
| 54 | - static fn (SplFileInfo $a, SplFileInfo $b): int|float => $b->getMTime() - $a->getMTime() |
|
| 54 | + static fn (SplFileInfo $a, SplFileInfo $b): int | float => $b->getMTime() - $a->getMTime() |
|
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | 57 | $count = 0; |
| 58 | - foreach ($finder as $file) { |
|
| 58 | + foreach ($finder as $file){ |
|
| 59 | 59 | $count++; |
| 60 | - if ($count > $this->maxFiles) { |
|
| 61 | - try { |
|
| 60 | + if ($count > $this->maxFiles){ |
|
| 61 | + try{ |
|
| 62 | 62 | $this->files->delete($file->getRealPath()); |
| 63 | - } catch (FilesException) { |
|
| 63 | + }catch (FilesException){ |
|
| 64 | 64 | // ignore |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | public function __construct( |
| 13 | 13 | private readonly string $id, |
| 14 | 14 | private readonly \Throwable $exception |
| 15 | - ) { |
|
| 15 | + ){ |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | public function getID(): string |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | private readonly string $namespace, |
| 11 | 11 | private readonly string $name, |
| 12 | 12 | private readonly string $basename |
| 13 | - ) { |
|
| 13 | + ){ |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function getNamespace(): string |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | public function __construct( |
| 16 | 16 | private readonly string $defaultNamespace, |
| 17 | 17 | private readonly string $extension |
| 18 | - ) { |
|
| 18 | + ){ |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function getExtension(): string |
@@ -50,21 +50,21 @@ discard block |
||
| 50 | 50 | ); |
| 51 | 51 | |
| 52 | 52 | $namespace = $this->defaultNamespace; |
| 53 | - if (!\str_contains((string) $filename, '.')) { |
|
| 53 | + if (!\str_contains((string)$filename, '.')){ |
|
| 54 | 54 | //Force default extension |
| 55 | - $filename .= '.' . $this->extension; |
|
| 56 | - } elseif (!$this->match($filename)) { |
|
| 55 | + $filename .= '.'.$this->extension; |
|
| 56 | + } elseif (!$this->match($filename)){ |
|
| 57 | 57 | return null; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if (\str_contains((string) $filename, LoaderInterface::NS_SEPARATOR)) { |
|
| 61 | - [$namespace, $filename] = explode(LoaderInterface::NS_SEPARATOR, (string) $filename); |
|
| 60 | + if (\str_contains((string)$filename, LoaderInterface::NS_SEPARATOR)){ |
|
| 61 | + [$namespace, $filename] = explode(LoaderInterface::NS_SEPARATOR, (string)$filename); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | //Twig like namespaces |
| 65 | - if (isset($filename[0]) && $filename[0] === '@') { |
|
| 65 | + if (isset($filename[0]) && $filename[0] === '@'){ |
|
| 66 | 66 | $separator = \strpos($filename, '/'); |
| 67 | - if ($separator === false) { |
|
| 67 | + if ($separator === false){ |
|
| 68 | 68 | throw new PathException(\sprintf('Malformed view path "%s" (expecting "@namespace/name").', $path)); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | private function validatePath(string $path): void |
| 96 | 96 | { |
| 97 | - if (empty($path)) { |
|
| 97 | + if (empty($path)){ |
|
| 98 | 98 | throw new PathException('A view path is empty'); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - if (\str_contains($path, "\0")) { |
|
| 101 | + if (\str_contains($path, "\0")){ |
|
| 102 | 102 | throw new PathException('A view path cannot contain NUL bytes'); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -106,14 +106,14 @@ discard block |
||
| 106 | 106 | $parts = \explode('/', $path); |
| 107 | 107 | $level = 0; |
| 108 | 108 | |
| 109 | - foreach ($parts as $part) { |
|
| 110 | - if ('..' === $part) { |
|
| 109 | + foreach ($parts as $part){ |
|
| 110 | + if ('..' === $part){ |
|
| 111 | 111 | --$level; |
| 112 | - } elseif ('.' !== $part) { |
|
| 112 | + } elseif ('.' !== $part){ |
|
| 113 | 113 | ++$level; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ($level < 0) { |
|
| 116 | + if ($level < 0){ |
|
| 117 | 117 | throw new PathException(\sprintf( |
| 118 | 118 | 'Looks like you try to load a view outside configured directories (%s)', |
| 119 | 119 | $path |
@@ -50,21 +50,27 @@ discard block |
||
| 50 | 50 | ); |
| 51 | 51 | |
| 52 | 52 | $namespace = $this->defaultNamespace; |
| 53 | - if (!\str_contains((string) $filename, '.')) { |
|
| 53 | + if (!\str_contains((string) $filename, '.')) |
|
| 54 | + { |
|
| 54 | 55 | //Force default extension |
| 55 | 56 | $filename .= '.' . $this->extension; |
| 56 | - } elseif (!$this->match($filename)) { |
|
| 57 | + } |
|
| 58 | + elseif (!$this->match($filename)) |
|
| 59 | + { |
|
| 57 | 60 | return null; |
| 58 | 61 | } |
| 59 | 62 | |
| 60 | - if (\str_contains((string) $filename, LoaderInterface::NS_SEPARATOR)) { |
|
| 63 | + if (\str_contains((string) $filename, LoaderInterface::NS_SEPARATOR)) |
|
| 64 | + { |
|
| 61 | 65 | [$namespace, $filename] = explode(LoaderInterface::NS_SEPARATOR, (string) $filename); |
| 62 | 66 | } |
| 63 | 67 | |
| 64 | 68 | //Twig like namespaces |
| 65 | - if (isset($filename[0]) && $filename[0] === '@') { |
|
| 69 | + if (isset($filename[0]) && $filename[0] === '@') |
|
| 70 | + { |
|
| 66 | 71 | $separator = \strpos($filename, '/'); |
| 67 | - if ($separator === false) { |
|
| 72 | + if ($separator === false) |
|
| 73 | + { |
|
| 68 | 74 | throw new PathException(\sprintf('Malformed view path "%s" (expecting "@namespace/name").', $path)); |
| 69 | 75 | } |
| 70 | 76 | |
@@ -94,11 +100,13 @@ discard block |
||
| 94 | 100 | */ |
| 95 | 101 | private function validatePath(string $path): void |
| 96 | 102 | { |
| 97 | - if (empty($path)) { |
|
| 103 | + if (empty($path)) |
|
| 104 | + { |
|
| 98 | 105 | throw new PathException('A view path is empty'); |
| 99 | 106 | } |
| 100 | 107 | |
| 101 | - if (\str_contains($path, "\0")) { |
|
| 108 | + if (\str_contains($path, "\0")) |
|
| 109 | + { |
|
| 102 | 110 | throw new PathException('A view path cannot contain NUL bytes'); |
| 103 | 111 | } |
| 104 | 112 | |
@@ -106,14 +114,19 @@ discard block |
||
| 106 | 114 | $parts = \explode('/', $path); |
| 107 | 115 | $level = 0; |
| 108 | 116 | |
| 109 | - foreach ($parts as $part) { |
|
| 110 | - if ('..' === $part) { |
|
| 117 | + foreach ($parts as $part) |
|
| 118 | + { |
|
| 119 | + if ('..' === $part) |
|
| 120 | + { |
|
| 111 | 121 | --$level; |
| 112 | - } elseif ('.' !== $part) { |
|
| 122 | + } |
|
| 123 | + elseif ('.' !== $part) |
|
| 124 | + { |
|
| 113 | 125 | ++$level; |
| 114 | 126 | } |
| 115 | 127 | |
| 116 | - if ($level < 0) { |
|
| 128 | + if ($level < 0) |
|
| 129 | + { |
|
| 117 | 130 | throw new PathException(\sprintf( |
| 118 | 131 | 'Looks like you try to load a view outside configured directories (%s)', |
| 119 | 132 | $path |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | public function getGlobalVariables(): array |
| 29 | 29 | { |
| 30 | - return (array) ($this->config['globalVariables'] ?? []); |
|
| 30 | + return (array)($this->config['globalVariables'] ?? []); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | public function isCacheEnabled(): bool |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | public function getCacheDirectory(): string |
| 39 | 39 | { |
| 40 | - return \rtrim($this->config['cache']['directory'] ?? '', '/') . '/'; |
|
| 40 | + return \rtrim($this->config['cache']['directory'] ?? '', '/').'/'; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function getNamespaces(): array |
| 47 | 47 | { |
| 48 | - return (array) ($this->config['namespaces'] ?? []); |
|
| 48 | + return (array)($this->config['namespaces'] ?? []); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | { |
| 58 | 58 | return \array_map( |
| 59 | 59 | fn (mixed $dependency): Autowire => $this->wire($dependency), |
| 60 | - (array) ($this->config['dependencies'] ?? []) |
|
| 60 | + (array)($this->config['dependencies'] ?? []) |
|
| 61 | 61 | ); |
| 62 | 62 | } |
| 63 | 63 | |
@@ -70,16 +70,16 @@ discard block |
||
| 70 | 70 | { |
| 71 | 71 | return \array_map( |
| 72 | 72 | fn (mixed $engine): Autowire => $this->wire($engine), |
| 73 | - (array) ($this->config['engines'] ?? []) |
|
| 73 | + (array)($this->config['engines'] ?? []) |
|
| 74 | 74 | ); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * @param Autowire|class-string $item |
| 79 | 79 | */ |
| 80 | - private function wire(Autowire|string $item): Autowire |
|
| 80 | + private function wire(Autowire | string $item): Autowire |
|
| 81 | 81 | { |
| 82 | - if ($item instanceof Autowire) { |
|
| 82 | + if ($item instanceof Autowire){ |
|
| 83 | 83 | return $item; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -79,7 +79,8 @@ |
||
| 79 | 79 | */ |
| 80 | 80 | private function wire(Autowire|string $item): Autowire |
| 81 | 81 | { |
| 82 | - if ($item instanceof Autowire) { |
|
| 82 | + if ($item instanceof Autowire) |
|
| 83 | + { |
|
| 83 | 84 | return $item; |
| 84 | 85 | } |
| 85 | 86 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | public function getID(): string |
| 21 | 21 | { |
| 22 | 22 | $calculated = ''; |
| 23 | - foreach ($this->dependencies as $dependency) { |
|
| 23 | + foreach ($this->dependencies as $dependency){ |
|
| 24 | 24 | $calculated .= \sprintf('[%s=%s]', $dependency->getName(), $dependency->getValue()); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | public function resolveValue(string $dependency): mixed |
| 49 | 49 | { |
| 50 | - if (!isset($this->dependencies[$dependency])) { |
|
| 50 | + if (!isset($this->dependencies[$dependency])){ |
|
| 51 | 51 | throw new ContextException(\sprintf('Undefined context dependency \'%s\'.', $dependency)); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -20,7 +20,8 @@ discard block |
||
| 20 | 20 | public function getID(): string |
| 21 | 21 | { |
| 22 | 22 | $calculated = ''; |
| 23 | - foreach ($this->dependencies as $dependency) { |
|
| 23 | + foreach ($this->dependencies as $dependency) |
|
| 24 | + { |
|
| 24 | 25 | $calculated .= \sprintf('[%s=%s]', $dependency->getName(), $dependency->getValue()); |
| 25 | 26 | } |
| 26 | 27 | |
@@ -47,7 +48,8 @@ discard block |
||
| 47 | 48 | |
| 48 | 49 | public function resolveValue(string $dependency): mixed |
| 49 | 50 | { |
| 50 | - if (!isset($this->dependencies[$dependency])) { |
|
| 51 | + if (!isset($this->dependencies[$dependency])) |
|
| 52 | + { |
|
| 51 | 53 | throw new ContextException(\sprintf('Undefined context dependency \'%s\'.', $dependency)); |
| 52 | 54 | } |
| 53 | 55 | |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | |
| 29 | 29 | public function getLoader(): LoaderInterface |
| 30 | 30 | { |
| 31 | - if (empty($this->loader)) { |
|
| 31 | + if (empty($this->loader)){ |
|
| 32 | 32 | throw new EngineException('No associated loader found'); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -28,7 +28,8 @@ |
||
| 28 | 28 | |
| 29 | 29 | public function getLoader(): LoaderInterface |
| 30 | 30 | { |
| 31 | - if (empty($this->loader)) { |
|
| 31 | + if (empty($this->loader)) |
|
| 32 | + { |
|
| 32 | 33 | throw new EngineException('No associated loader found'); |
| 33 | 34 | } |
| 34 | 35 | |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | public function __construct( |
| 17 | 17 | private readonly ContainerInterface $container, |
| 18 | 18 | string $extension = self::EXTENSION |
| 19 | - ) { |
|
| 19 | + ){ |
|
| 20 | 20 | $this->extension = $extension; |
| 21 | 21 | } |
| 22 | 22 | |