From 44196834c786abc15a66805f0e9d467b4923d03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pudil?= Date: Sat, 30 Dec 2023 19:32:56 +0100 Subject: [PATCH] bump --- .github/workflows/main.yml | 16 ++++----- Makefile | 2 +- README.md | 4 +-- composer.json | 6 ++-- ecs.php | 34 +++++-------------- src/AssetLocator.php | 28 ++++----------- .../DebuggerAwareAssetNameResolver.php | 8 ++--- .../ManifestAssetNameResolver.php | 12 +++---- .../StaticAssetNameResolver.php | 9 ++--- src/BasePath/NetteHttpBasePathProvider.php | 8 ++--- src/BuildDirectoryProvider.php | 12 +++---- src/DI/WebpackExtension.php | 6 ++-- src/Debugging/WebpackPanel.php | 22 +++++------- src/DevServer/DevServer.php | 30 +++++----------- src/DevServer/Http/MockClient.php | 8 ++--- src/Latte/WebpackExtension.php | 8 ++--- src/Manifest/ManifestLoader.php | 17 +++------- src/PublicPathProvider.php | 16 +++------ 18 files changed, 82 insertions(+), 164 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 34fc474..587c77d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,11 +15,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ '7.4', '8.0', '8.1' ] + php: [ '8.1', '8.2', '8.3' ] latte: [ '', '--prefer-lowest' ] fail-fast: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} @@ -32,10 +32,10 @@ jobs: coverage: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.3' extensions: curl, iconv, json, mbstring, tokenizer coverage: pcov - run: composer install --no-interaction @@ -45,10 +45,10 @@ jobs: phpstan: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.3' coverage: none - run: composer install --no-interaction - run: make phpstan @@ -56,10 +56,10 @@ jobs: coding-standard: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.3' coverage: none - run: composer install --no-interaction - run: make cs diff --git a/Makefile b/Makefile index 94d6de0..1f076c3 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ csf: vendor/bin/ecs check src tests --fix phpstan: - vendor/bin/phpstan analyze -l max src + vendor/bin/phpstan analyze -l 8 src tests: vendor/bin/tester -C tests diff --git a/README.md b/README.md index 0f864b3..1b3c7f5 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,8 @@ For details on how to use this package, check out our [documentation](.docs). | State | Version | Branch | Nette | PHP | |-------------|--------------|----------|----------|----------| -| dev | `^2.0.x-dev` | `master | `3.0+` | `>= 7.4` | -| stable | `^2.0` | `master` | `3.0+` | `>= 7.4` | +| dev | `^2.0.x-dev` | `master` | `3.0+` | `>= 8.1` | +| stable | `^2.0` | `master` | `3.0+` | `>= 8.1` | ## Development diff --git a/composer.json b/composer.json index cd08759..fd2e6be 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "issues": "https://github.com/contributte/webpack/issues" }, "require": { - "php": ">=7.4", + "php": ">=8.1", "ext-curl": "*", "nette/di": "^3.0" }, @@ -29,8 +29,8 @@ "nette/application": "^3.0", "nette/bootstrap": "^3.0", "nette/tester": "^2.0", - "phpstan/phpstan": "^0.12", - "symplify/easy-coding-standard": "^8.3", + "phpstan/phpstan": "^1.0", + "symplify/easy-coding-standard": "^12.0", "tracy/tracy": "^2.4" }, "suggest": { diff --git a/ecs.php b/ecs.php index b31d256..65d6118 100644 --- a/ecs.php +++ b/ecs.php @@ -2,37 +2,21 @@ declare(strict_types=1); -use PhpCsFixer\Fixer\Basic\BracesFixer; use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocLineSpanFixer; use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer; -use SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symplify\EasyCodingStandard\Config\ECSConfig; use Symplify\EasyCodingStandard\ValueObject\Option; use Symplify\EasyCodingStandard\ValueObject\Set\SetList; -return static function (ContainerConfigurator $containerConfigurator): void { - $services = $containerConfigurator->services(); - $parameters = $containerConfigurator->parameters(); +return static function (ECSConfig $ecsConfig): void { + $ecsConfig->fileExtensions(['php', 'phpt']); + $ecsConfig->skip(['temp/*']); - $parameters->set(Option::FILE_EXTENSIONS, ['php', 'phpt']); - $parameters->set(Option::EXCLUDE_PATHS, ['temp/*']); + $ecsConfig->sets([SetList::CLEAN_CODE, SetList::PSR_12]); + $ecsConfig->indentation(Option::INDENTATION_TAB); - $parameters->set(Option::INDENTATION, Option::INDENTATION_TAB); - $parameters->set(Option::SETS, [SetList::CLEAN_CODE, SetList::PSR_12, SetList::PHP_71, SetList::PHP_73_MIGRATION]); - $services->set(SingleQuoteFixer::class); - $services->set(ClassAttributesSeparationFixer::class); - $services->set(PhpdocLineSpanFixer::class) - ->call('configure', [[ - 'property' => 'single' - ]]); - - $parameters->set(Option::SKIP, [ - UnusedVariableSniff::class => [ - __DIR__ . '/src/Debugging/WebpackPanel.php', - ], - BracesFixer::class => [ - __DIR__ . '/src/Debugging/WebpackPanel.php', - ], - ]); + $ecsConfig->rule(SingleQuoteFixer::class); + $ecsConfig->rule(ClassAttributesSeparationFixer::class); + $ecsConfig->ruleWithConfiguration(PhpdocLineSpanFixer::class, ['property' => 'single']); }; diff --git a/src/AssetLocator.php b/src/AssetLocator.php index 95bfb1a..b342992 100644 --- a/src/AssetLocator.php +++ b/src/AssetLocator.php @@ -9,32 +9,16 @@ final class AssetLocator { - private BuildDirectoryProvider $directoryProvider; - - private PublicPathProvider $publicPathProvider; - - private AssetNameResolverInterface $assetResolver; - - private DevServer $devServer; - - /** @var string[] */ - private array $ignoredAssetNames; - /** * @param string[] $ignoredAssetNames */ public function __construct( - BuildDirectoryProvider $directoryProvider, - PublicPathProvider $publicPathProvider, - AssetNameResolverInterface $assetResolver, - DevServer $devServer, - array $ignoredAssetNames + private readonly BuildDirectoryProvider $directoryProvider, + private readonly PublicPathProvider $publicPathProvider, + private readonly AssetNameResolverInterface $assetResolver, + private readonly DevServer $devServer, + private readonly array $ignoredAssetNames, ) { - $this->directoryProvider = $directoryProvider; - $this->publicPathProvider = $publicPathProvider; - $this->assetResolver = $assetResolver; - $this->devServer = $devServer; - $this->ignoredAssetNames = $ignoredAssetNames; } private function locateInPath(string $path, string $asset): string @@ -64,6 +48,6 @@ public function locateInBuildDirectory(string $asset): string private function isAbsoluteUrl(string $url): bool { - return strpos($url, '://') !== false || substr($url, 0, 2) === '//'; + return \str_contains($url, '://') || \str_starts_with($url, '//'); } } diff --git a/src/AssetNameResolver/DebuggerAwareAssetNameResolver.php b/src/AssetNameResolver/DebuggerAwareAssetNameResolver.php index e302af3..8248f15 100644 --- a/src/AssetNameResolver/DebuggerAwareAssetNameResolver.php +++ b/src/AssetNameResolver/DebuggerAwareAssetNameResolver.php @@ -6,14 +6,12 @@ final class DebuggerAwareAssetNameResolver implements AssetNameResolverInterface { - private AssetNameResolverInterface $inner; - /** @var array */ private array $resolvedAssets = []; - public function __construct(AssetNameResolverInterface $inner) - { - $this->inner = $inner; + public function __construct( + private readonly AssetNameResolverInterface $inner, + ) { } public function resolveAssetName(string $asset): string diff --git a/src/AssetNameResolver/ManifestAssetNameResolver.php b/src/AssetNameResolver/ManifestAssetNameResolver.php index e2db304..8e3f2a8 100644 --- a/src/AssetNameResolver/ManifestAssetNameResolver.php +++ b/src/AssetNameResolver/ManifestAssetNameResolver.php @@ -9,17 +9,13 @@ final class ManifestAssetNameResolver implements AssetNameResolverInterface { - private string $manifestName; - - private ManifestLoader $loader; - /** @var array|null */ private ?array $manifestCache = null; - public function __construct(string $manifestName, ManifestLoader $loader) - { - $this->manifestName = $manifestName; - $this->loader = $loader; + public function __construct( + private readonly string $manifestName, + private readonly ManifestLoader $loader, + ) { } public function resolveAssetName(string $asset): string diff --git a/src/AssetNameResolver/StaticAssetNameResolver.php b/src/AssetNameResolver/StaticAssetNameResolver.php index 3a22720..83f203c 100644 --- a/src/AssetNameResolver/StaticAssetNameResolver.php +++ b/src/AssetNameResolver/StaticAssetNameResolver.php @@ -6,15 +6,12 @@ final class StaticAssetNameResolver implements AssetNameResolverInterface { - /** @var array */ - private array $resolutions; - /** * @param array $resolutions */ - public function __construct(array $resolutions) - { - $this->resolutions = $resolutions; + public function __construct( + private readonly array $resolutions, + ) { } public function resolveAssetName(string $asset): string diff --git a/src/BasePath/NetteHttpBasePathProvider.php b/src/BasePath/NetteHttpBasePathProvider.php index ebe9e4d..ccefb13 100644 --- a/src/BasePath/NetteHttpBasePathProvider.php +++ b/src/BasePath/NetteHttpBasePathProvider.php @@ -8,11 +8,9 @@ final class NetteHttpBasePathProvider implements BasePathProvider { - private IRequest $httpRequest; - - public function __construct(IRequest $httpRequest) - { - $this->httpRequest = $httpRequest; + public function __construct( + private readonly IRequest $httpRequest, + ) { } public function getBasePath(): string diff --git a/src/BuildDirectoryProvider.php b/src/BuildDirectoryProvider.php index 9666fc8..81c4f1a 100644 --- a/src/BuildDirectoryProvider.php +++ b/src/BuildDirectoryProvider.php @@ -11,14 +11,10 @@ */ final class BuildDirectoryProvider { - private string $directory; - - private DevServer $devServer; - - public function __construct(string $directory, DevServer $devServer) - { - $this->directory = $directory; - $this->devServer = $devServer; + public function __construct( + private readonly string $directory, + private readonly DevServer $devServer, + ) { } public function getBuildDirectory(): string diff --git a/src/DI/WebpackExtension.php b/src/DI/WebpackExtension.php index 1d7073a..e0a8113 100644 --- a/src/DI/WebpackExtension.php +++ b/src/DI/WebpackExtension.php @@ -13,6 +13,7 @@ use Contributte\Webpack\DevServer\DevServer; use Contributte\Webpack\DevServer\Http\CurlClient; use Contributte\Webpack\Manifest\ManifestLoader; +use Contributte\Webpack\Manifest\ManifestMapper; use Contributte\Webpack\Manifest\Mapper\WebpackManifestPluginMapper; use Contributte\Webpack\PublicPathProvider; use Latte\Engine; @@ -31,9 +32,9 @@ */ final class WebpackExtension extends CompilerExtension { - private bool $debugMode; + private readonly bool $debugMode; - private bool $consoleMode; + private readonly bool $consoleMode; public function __construct(bool $debugMode, ?bool $consoleMode = null) { @@ -169,6 +170,7 @@ private function setupAssetResolver(array $config): ServiceDefinition } else { $devServerInstance = new DevServer(false, '', '', 0.0, new CurlClient()); + /** @var ManifestMapper $mapperInstance */ $mapperInstance = new $config['manifest']['mapper'](); $directoryProviderInstance = new BuildDirectoryProvider($config['build']['directory'], $devServerInstance); diff --git a/src/Debugging/WebpackPanel.php b/src/Debugging/WebpackPanel.php index 6ae13bd..d9444ac 100644 --- a/src/Debugging/WebpackPanel.php +++ b/src/Debugging/WebpackPanel.php @@ -11,22 +11,17 @@ final class WebpackPanel implements IBarPanel { - private PublicPathProvider $pathProvider; - - private DebuggerAwareAssetNameResolver $assetResolver; - - private DevServer $devServer; - - public function __construct(PublicPathProvider $pathProvider, DebuggerAwareAssetNameResolver $assetResolver, DevServer $devServer) - { - $this->pathProvider = $pathProvider; - $this->assetResolver = $assetResolver; - $this->devServer = $devServer; + public function __construct( + private readonly PublicPathProvider $pathProvider, + private readonly DebuggerAwareAssetNameResolver $assetResolver, + private readonly DevServer $devServer, + ) { } public function getTab(): ?string { - \ob_start(function (): void {}); + \ob_start(function (): void { + }); $devServer = $this->devServer; $assets = $this->assetResolver->getResolvedAssets(); require __DIR__ . '/templates/WebpackPanel.tab.phtml'; @@ -35,7 +30,8 @@ public function getTab(): ?string public function getPanel(): ?string { - \ob_start(function (): void {}); + \ob_start(function (): void { + }); $devServer = $this->devServer; $path = $this->pathProvider->getPublicPath(); $assets = $this->assetResolver->getResolvedAssets(); diff --git a/src/DevServer/DevServer.php b/src/DevServer/DevServer.php index 3d725ed..1393ebb 100644 --- a/src/DevServer/DevServer.php +++ b/src/DevServer/DevServer.php @@ -8,25 +8,15 @@ final class DevServer { - private bool $enabled; - private ?bool $available = null; - private string $url; - - private ?string $publicUrl; - - private float $timeout; - - private Client $httpClient; - - public function __construct(bool $enabled, string $url, ?string $publicUrl, float $timeout, Client $httpClient) - { - $this->enabled = $enabled; - $this->url = $url; - $this->publicUrl = $publicUrl; - $this->timeout = $timeout; - $this->httpClient = $httpClient; + public function __construct( + private readonly bool $enabled, + private readonly string $url, + private readonly ?string $publicUrl, + private readonly float $timeout, + private readonly Client $httpClient, + ) { } public function getUrl(): string @@ -50,10 +40,6 @@ public function isAvailable(): bool return false; } - if ($this->available === null) { - $this->available = $this->httpClient->isAvailable($this->url, $this->timeout); - } - - return $this->available; + return $this->available ??= $this->httpClient->isAvailable($this->url, $this->timeout); } } diff --git a/src/DevServer/Http/MockClient.php b/src/DevServer/Http/MockClient.php index 43ddd1c..1651984 100644 --- a/src/DevServer/Http/MockClient.php +++ b/src/DevServer/Http/MockClient.php @@ -9,11 +9,9 @@ */ final class MockClient implements Client { - private bool $isAvailable; - - public function __construct(bool $isAvailable) - { - $this->isAvailable = $isAvailable; + public function __construct( + private readonly bool $isAvailable + ) { } public function isAvailable(string $url, float $timeout): bool diff --git a/src/Latte/WebpackExtension.php b/src/Latte/WebpackExtension.php index f2a7031..568e36b 100644 --- a/src/Latte/WebpackExtension.php +++ b/src/Latte/WebpackExtension.php @@ -9,11 +9,9 @@ final class WebpackExtension extends Extension { - private AssetLocator $assetLocator; - - public function __construct(AssetLocator $assetLocator) - { - $this->assetLocator = $assetLocator; + public function __construct( + private readonly AssetLocator $assetLocator, + ) { } public function getTags(): array diff --git a/src/Manifest/ManifestLoader.php b/src/Manifest/ManifestLoader.php index 9404776..85513b2 100644 --- a/src/Manifest/ManifestLoader.php +++ b/src/Manifest/ManifestLoader.php @@ -12,20 +12,11 @@ */ final class ManifestLoader { - private BuildDirectoryProvider $directoryProvider; - - private ManifestMapper $manifestMapper; - - private float $timeout; - public function __construct( - BuildDirectoryProvider $directoryProvider, - ManifestMapper $manifestMapper, - float $timeout + private readonly BuildDirectoryProvider $directoryProvider, + private readonly ManifestMapper $manifestMapper, + private readonly float $timeout ) { - $this->directoryProvider = $directoryProvider; - $this->manifestMapper = $manifestMapper; - $this->timeout = $timeout; } /** @@ -78,7 +69,7 @@ public function loadManifest(string $fileName): array )); } - return $this->manifestMapper->map(Json::decode($manifest, Json::FORCE_ARRAY)); + return $this->manifestMapper->map(Json::decode($manifest, forceArrays: true)); } public function getManifestPath(string $fileName): string diff --git a/src/PublicPathProvider.php b/src/PublicPathProvider.php index 17d2496..c8b4b24 100644 --- a/src/PublicPathProvider.php +++ b/src/PublicPathProvider.php @@ -12,17 +12,11 @@ */ final class PublicPathProvider { - private string $path; - - private BasePathProvider $basePathProvider; - - private DevServer $devServer; - - public function __construct(string $path, BasePathProvider $basePathProvider, DevServer $devServer) - { - $this->path = $path; - $this->basePathProvider = $basePathProvider; - $this->devServer = $devServer; + public function __construct( + private readonly string $path, + private readonly BasePathProvider $basePathProvider, + private readonly DevServer $devServer, + ) { } public function getPublicPath(): string