Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
jiripudil committed Dec 30, 2023
1 parent f29901b commit 4419683
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 164 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand All @@ -45,21 +45,21 @@ 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

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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"issues": "https://github.com/contributte/webpack/issues"
},
"require": {
"php": ">=7.4",
"php": ">=8.1",
"ext-curl": "*",
"nette/di": "^3.0"
},
Expand All @@ -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": {
Expand Down
34 changes: 9 additions & 25 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
};
28 changes: 6 additions & 22 deletions src/AssetLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, '//');
}
}
8 changes: 3 additions & 5 deletions src/AssetNameResolver/DebuggerAwareAssetNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

final class DebuggerAwareAssetNameResolver implements AssetNameResolverInterface
{
private AssetNameResolverInterface $inner;

/** @var array<array{string, string}> */
private array $resolvedAssets = [];

public function __construct(AssetNameResolverInterface $inner)
{
$this->inner = $inner;
public function __construct(
private readonly AssetNameResolverInterface $inner,
) {
}

public function resolveAssetName(string $asset): string
Expand Down
12 changes: 4 additions & 8 deletions src/AssetNameResolver/ManifestAssetNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@

final class ManifestAssetNameResolver implements AssetNameResolverInterface
{
private string $manifestName;

private ManifestLoader $loader;

/** @var array<string, string>|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
Expand Down
9 changes: 3 additions & 6 deletions src/AssetNameResolver/StaticAssetNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

final class StaticAssetNameResolver implements AssetNameResolverInterface
{
/** @var array<string, string> */
private array $resolutions;

/**
* @param array<string, string> $resolutions
*/
public function __construct(array $resolutions)
{
$this->resolutions = $resolutions;
public function __construct(
private readonly array $resolutions,
) {
}

public function resolveAssetName(string $asset): string
Expand Down
8 changes: 3 additions & 5 deletions src/BasePath/NetteHttpBasePathProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions src/BuildDirectoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/DI/WebpackExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 9 additions & 13 deletions src/Debugging/WebpackPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand Down
30 changes: 8 additions & 22 deletions src/DevServer/DevServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
Loading

0 comments on commit 4419683

Please sign in to comment.