diff --git a/phpstan/phpstan.neon b/phpstan/phpstan.neon index 3299687..c3eacd4 100755 --- a/phpstan/phpstan.neon +++ b/phpstan/phpstan.neon @@ -8,7 +8,7 @@ parameters: excludePaths: - %currentWorkingDirectory%/tests/temp/* - level: 7 + level: 8 checkMissingIterableValueType: false diff --git a/src/Compiler.php b/src/Compiler.php index 78a89c3..717be7c 100755 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -1,6 +1,6 @@ namingConvention->getFilename($files, $this); $path = $this->outputDir . '/' . $name; - $lastModified = $this->checkLastModified ? $this->getLastModified($watchFiles) : 0; + $lastModified = $this->checkLastModified + ? $this->getLastModified($watchFiles) + : 0; if (!file_exists($path) || $lastModified > filemtime($path) || $this->debugging === true) { // disabled: https://github.com/nette/safe-stream/pull/5 diff --git a/src/Contract/IBatchCollection.php b/src/Contract/IBatchCollection.php index e986330..a8a40a4 100755 --- a/src/Contract/IBatchCollection.php +++ b/src/Contract/IBatchCollection.php @@ -1,10 +1,11 @@ setSuffix('.css'); return $convention; @@ -29,7 +28,7 @@ public static function createCssConvention(): self public static function createJsConvention(): self { - $convention = new self(); + $convention = new self; $convention->setSuffix('.js'); return $convention; diff --git a/src/Exception/BatchAlreadyExistsException.php b/src/Exception/BatchAlreadyExistsException.php index 7117731..718be6f 100755 --- a/src/Exception/BatchAlreadyExistsException.php +++ b/src/Exception/BatchAlreadyExistsException.php @@ -1,9 +1,8 @@ root = (string) $root; } diff --git a/src/Filter/CssMinFilter.php b/src/Filter/CssMinFilter.php index fd0dcd0..0b72468 100755 --- a/src/Filter/CssMinFilter.php +++ b/src/Filter/CssMinFilter.php @@ -8,7 +8,6 @@ class CssMinFilter { - public function __invoke(string $code, Compiler $compiler, string $file = ''): string { $minifier = new Minifier; diff --git a/src/Filter/CssUrlsFilter.php b/src/Filter/CssUrlsFilter.php index 1aad49f..02beef0 100755 --- a/src/Filter/CssUrlsFilter.php +++ b/src/Filter/CssUrlsFilter.php @@ -1,6 +1,6 @@ docRoot = Path::normalize($docRoot); if (!is_dir($this->docRoot)) { throw new InvalidArgumentException('Given document root is not directory.'); } - - $this->basePath = $basePath; } @@ -109,9 +107,7 @@ public function __invoke(string $code, Compiler $loader, ?string $file = null): $self = $this; - $return = preg_replace_callback($regexp, function ($matches) use ($self, $file) { - return "url('" . $self->absolutizeUrl($matches[2], $matches[1], $file) . "')"; - }, $code); + $return = preg_replace_callback($regexp, fn($matches) => "url('" . $self->absolutizeUrl($matches[2], $matches[1], $file) . "')", $code); return (string) $return; } diff --git a/src/Filter/LessBinFilter.php b/src/Filter/LessBinFilter.php index b56a873..a09ee1f 100644 --- a/src/Filter/LessBinFilter.php +++ b/src/Filter/LessBinFilter.php @@ -1,6 +1,6 @@ bin = $bin; $this->env = $env + $_ENV; unset($this->env['argv'], $this->env['argc']); } diff --git a/src/Filter/Process.php b/src/Filter/Process.php index 9eadfc4..f504558 100644 --- a/src/Filter/Process.php +++ b/src/Filter/Process.php @@ -1,6 +1,6 @@ ['pipe', 'r'], // stdin 1 => ['pipe', 'w'], // stdout diff --git a/src/Filter/ScssFilter.php b/src/Filter/ScssFilter.php index b73eaae..43fb255 100644 --- a/src/Filter/ScssFilter.php +++ b/src/Filter/ScssFilter.php @@ -1,6 +1,6 @@ sc = $sc; } @@ -29,7 +24,7 @@ private function getScssC(): ScssCompiler { // lazy loading if (empty($this->sc)) { - $this->sc = new ScssCompiler(); + $this->sc = new ScssCompiler; } return $this->sc; diff --git a/src/Filter/StylusFilter.php b/src/Filter/StylusFilter.php index ccf6f47..7ac4b30 100755 --- a/src/Filter/StylusFilter.php +++ b/src/Filter/StylusFilter.php @@ -1,6 +1,6 @@ bin = $bin; } diff --git a/src/Filter/TypeScriptFilter.php b/src/Filter/TypeScriptFilter.php index 833106a..b11f174 100755 --- a/src/Filter/TypeScriptFilter.php +++ b/src/Filter/TypeScriptFilter.php @@ -1,6 +1,6 @@ bin = $bin; $this->env = $env + $_ENV; unset($this->env['argv'], $this->env['argc']); } diff --git a/src/Filter/VariablesFilter.php b/src/Filter/VariablesFilter.php index be326d4..3ec1203 100644 --- a/src/Filter/VariablesFilter.php +++ b/src/Filter/VariablesFilter.php @@ -1,6 +1,6 @@ $value) { $this->$key = $value; @@ -30,8 +28,8 @@ public function __construct(array $variables = []) public function setDelimiter(string $start, string $end): self { - $this->startVariable = (string) $start; - $this->endVariable = (string) $end; + $this->startVariable = $start; + $this->endVariable = $end; return $this; } @@ -41,9 +39,7 @@ public function __invoke(string $code): string $start = $this->startVariable; $end = $this->endVariable; - $variables = array_map(function ($key) use ($start, $end) { - return $start . $key . $end; - }, array_keys($this->variables)); + $variables = array_map(fn($key) => $start . $key . $end, array_keys($this->variables)); $values = array_values($this->variables); diff --git a/src/Nette/CssLoader.php b/src/Nette/CssLoader.php index b8687c6..8b77dab 100755 --- a/src/Nette/CssLoader.php +++ b/src/Nette/CssLoader.php @@ -1,6 +1,6 @@ media; } @@ -34,7 +34,7 @@ public function getType(): string } - public function getTitle(): string + public function getTitle(): ?string { return $this->title; } @@ -105,5 +105,4 @@ public function getInlineElement(File $file): Html return $el; } - } diff --git a/src/Nette/CssUrlFilter.php b/src/Nette/CssUrlFilter.php index 17e5091..2733164 100755 --- a/src/Nette/CssUrlFilter.php +++ b/src/Nette/CssUrlFilter.php @@ -1,6 +1,6 @@ 'CSS files', 'js' => 'JavaScript files', @@ -36,7 +34,9 @@ class Panel implements IBarPanel public function __construct(?string $appDir = null) { - $this->root = $appDir ? str_replace('\\', DIRECTORY_SEPARATOR, (string) realpath(dirname($appDir))) : ''; + $this->root = $appDir + ? str_replace('\\', DIRECTORY_SEPARATOR, (string) realpath(dirname($appDir))) + : ''; Debugger::getBar()->addPanel($this); } @@ -88,7 +88,7 @@ private function compute(): array $generated = $compiler->generate(); - if (is_null($generated)) { + if (null === $generated) { continue; } @@ -133,9 +133,7 @@ private function getTable(): string { $latte = new Latte\Engine; - $latte->addFilter('extension', function ($extension) { - return isset(self::$types[$extension]) ? self::$types[$extension] : $extension; - }); + $latte->addFilter('extension', fn($extension) => self::$types[$extension] ?? $extension); return $latte->renderToString(__DIR__ . '/panel.latte', [ 'files' => $this->files, @@ -161,6 +159,10 @@ public function getTab(): string { $this->compute(); + if (empty($this->size['combined'])) { + return ''; + } + return '' . '' . Filters::bytes($this->size['combined']) diff --git a/src/Nette/Extension.php b/src/Nette/Extension.php index 6f93257..c258f7f 100644 --- a/src/Nette/Extension.php +++ b/src/Nette/Extension.php @@ -1,6 +1,6 @@ prefix('jsNamingConvention')) : null; + $namingConvention = $useDefaults + ? ('@' . $this->prefix('jsNamingConvention')) + : null; return Expect::structure([ 'checkLastModified' => Expect::bool($checkLastModified), @@ -89,7 +90,9 @@ private function getCssConfigSchema(bool $useDefaults = false): Schema $async = $useDefaults ? false : null; $defer = $useDefaults ? false : null; $absoluteUrl = $useDefaults ? false : null; - $namingConvention = $useDefaults ? ('@' . $this->prefix('cssNamingConvention')) : null; + $namingConvention = $useDefaults + ? ('@' . $this->prefix('cssNamingConvention')) + : null; return Expect::structure([ 'checkLastModified' => Expect::bool($checkLastModified), @@ -343,7 +346,7 @@ private function extractBatchesFromExtensions(): void $schemaProcessor = new Processor; - foreach($batchProviders as $batchProvider) { + foreach ($batchProviders as $batchProvider) { $assets = $batchProvider->getWebloaderAssets(); $schemaProcessor->process($this->getConfigSchema(), $assets); diff --git a/src/Nette/JavaScriptLoader.php b/src/Nette/JavaScriptLoader.php index 8833ba4..45ee64e 100644 --- a/src/Nette/JavaScriptLoader.php +++ b/src/Nette/JavaScriptLoader.php @@ -1,6 +1,6 @@ */ - private array $tempPaths; - - - /** - * @param array $tempPaths - * @param string $extensionName - * @param IRequest $httpRequest - * @param Container $diContainer - */ + /** @param array $tempPaths */ public function __construct( - array $tempPaths, - string $extensionName, - IRequest $httpRequest, - Container $diContainer + private array $tempPaths, + private string $extensionName, + private IRequest $httpRequest, + private Container $diContainer ) { - $this->httpRequest = $httpRequest; - $this->diContainer = $diContainer; - $this->tempPaths = $tempPaths; - $this->extensionName = $extensionName; } diff --git a/src/Nette/SymfonyConsole/GenerateCommand.php b/src/Nette/SymfonyConsole/GenerateCommand.php index eaa1a74..2cd5ac4 100644 --- a/src/Nette/SymfonyConsole/GenerateCommand.php +++ b/src/Nette/SymfonyConsole/GenerateCommand.php @@ -1,6 +1,6 @@ compilers as $compiler) { $file = $compiler->generate(); - if (!is_null($file)) { + if (null !== $file) { $output->writeln($file->getFileName()); $noFiles = false; } diff --git a/src/Nette/WebLoader.php b/src/Nette/WebLoader.php index 7fbe903..d0a9b63 100755 --- a/src/Nette/WebLoader.php +++ b/src/Nette/WebLoader.php @@ -1,6 +1,6 @@ compiler = $compiler; - $this->tempPath = $tempPath; - $this->appendLastModified = $appendLastModified; + public function __construct( + private Compiler $compiler, + private string $tempPath, + private bool $appendLastModified + ) { } diff --git a/src/Path.php b/src/Path.php index 5dd5b80..1b9a650 100755 --- a/src/Path.php +++ b/src/Path.php @@ -1,6 +1,6 @@ object->setFileCollection(new FileCollection()); + $this->object->setFileCollection(new FileCollection('')); $ret = $this->object->generate(); $this->assertNull($ret); @@ -91,7 +93,7 @@ public function testGeneratingAndFilters(): void $expectedContent = '-' . PHP_EOL . 'a:cba,' . PHP_EOL . 'b:fed,' . PHP_EOL . 'c:ihg,-' . PHP_EOL . 'a:cba,' . PHP_EOL . 'b:fed,' . PHP_EOL . 'c:ihg,'; - $file = $this->object->generate(); + $file = $this->generateFile(); $this->assertTrue(is_numeric($file->getLastModified()) && $file->getLastModified() > 0, 'Generate does not provide last modified timestamp correctly.'); @@ -103,7 +105,8 @@ public function testGeneratingAndFilters(): void public function testGenerateReturnsSourceFilePaths(): void { - $file = $this->object->generate(); + $file = $this->generateFile(); + $this->assertIsArray($file->getSourceFiles()); $this->assertCount(3, $file->getSourceFiles()); $this->assertFileExists($file->getSourceFiles()[0]); @@ -144,4 +147,16 @@ public function testNonCallableFileFilter(): void $this->expectException(TypeError::class); $this->object->addFileFilter(4); } + + + private function generateFile(): File + { + $file = $this->object->generate(); + + if ($file === null) { + throw new Exception('Should not be empty'); + } + + return $file; + } }