Skip to content

Commit

Permalink
Merge pull request #258 from Spomky-Labs/temp-489ead
Browse files Browse the repository at this point in the history
Merge up 1.2.7 to 1.3.x
  • Loading branch information
Spomky authored Dec 16, 2024
2 parents 7dd44c2 + 884a374 commit 33291c5
Show file tree
Hide file tree
Showing 25 changed files with 1,008 additions and 274 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
php-version:
- "8.2"
- "8.3"
- "8.4"
dependencies:
- "highest"
runs-on: ${{ matrix.operating-system }}
Expand Down
26 changes: 14 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"php": ">=8.2",
"phpdocumentor/reflection-docblock": "^5.3",
"psr/log": "^1.0|^2.0|^3.0",
"symfony/asset": "^6.4|^7.0",
"symfony/asset-mapper": "^6.4|^7.0",
"symfony/config": "^6.4|^7.0",
"symfony/dependency-injection": "^6.4|^7.0",
Expand All @@ -48,23 +49,24 @@
"require-dev": {
"ext-sockets": "*",
"dbrekelmans/bdi": "^1.1",
"ekino/phpstan-banned-code": "^1.0 || ^2.0",
"ekino/phpstan-banned-code": "^1.0|^2.0|^3.0",
"ergebnis/phpunit-slow-test-detector": "^2.14",
"infection/infection": "^0.28 || ^0.29",
"infection/infection": "^0.28|^0.29",
"matthiasnoback/symfony-config-test": "^5.1",
"nelmio/security-bundle": "^3.0",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpstan/extension-installer": "^1.1",
"phpstan/phpdoc-parser": "^1.28",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-beberlei-assert": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.0",
"phpstan/phpstan-symfony": "^1.3",
"phpstan/phpdoc-parser": "^1.28|^2.0",
"phpstan/phpstan": "^1.0|^2.0",
"phpstan/phpstan-beberlei-assert": "^1.0|^2.0",
"phpstan/phpstan-deprecation-rules": "^1.0|^2.0",
"phpstan/phpstan-phpunit": "^1.4|^2.0",
"phpstan/phpstan-strict-rules": "^1.0|^2.0",
"phpstan/phpstan-symfony": "^1.4|^2.0",
"phpunit/phpunit": "^10.1|^11.0",
"rector/rector": "^1.0",
"staabm/phpstan-todo-by": "^0.1.25",
"struggle-for-php/sfp-phpstan-psr-log": "^0.20.0 || ^0.21.0 || ^0.22.0",
"rector/rector": "^1.0|^2.0",
"staabm/phpstan-todo-by": "^0.1.27|^0.2",
"struggle-for-php/sfp-phpstan-psr-log": "^0.21.0|^0.22|^0.23",
"symfony/filesystem": "^6.4|^7.0",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/mime": "^6.4|^7.0",
Expand Down
1,050 changes: 888 additions & 162 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
parameters:
level: max
paths:
- src
- tests
checkMissingIterableValueType: true
checkGenericClassInNonGenericObjectType: true
checkUninitializedProperties: true
treatPhpDocTypesAsCertain: false
banned_code:
non_ignorable: false
scanFiles:
- vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php
level: max
paths:
- src
- tests

banned_code:
non_ignorable: false
checkUninitializedProperties: true
treatPhpDocTypesAsCertain: false
scanFiles:
- vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php

includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
- phpstan-baseline.neon
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
- phpstan-baseline.neon
2 changes: 1 addition & 1 deletion src/CachingStrategy/AssetCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private function getAssets(): array
{
$assets = [];
foreach ($this->assetMapper->allAssets() as $asset) {
if (preg_match($this->workbox->assetCache->regex, $asset->sourcePath) === 1) {
if (preg_match($this->workbox->assetCache->regex, $asset->publicPath) === 1) {
$assets[] = $asset->publicPath;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/CachingStrategy/BackgroundSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use SpomkyLabs\PwaBundle\MatchCallbackHandler\MatchCallbackHandlerInterface;
use SpomkyLabs\PwaBundle\Service\CanLogInterface;
use SpomkyLabs\PwaBundle\WorkboxPlugin\BackgroundSyncPlugin;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;

final class BackgroundSync implements HasCacheStrategiesInterface, CanLogInterface
{
Expand All @@ -24,7 +24,7 @@ final class BackgroundSync implements HasCacheStrategiesInterface, CanLogInterfa
*/
public function __construct(
ServiceWorker $serviceWorker,
#[TaggedIterator('spomky_labs_pwa.match_callback_handler')]
#[AutowireIterator('spomky_labs_pwa.match_callback_handler')]
private readonly iterable $matchCallbackHandlers,
) {
$this->workbox = $serviceWorker->workbox;
Expand Down
2 changes: 1 addition & 1 deletion src/CachingStrategy/FontCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private function getFonts(): array
{
$fonts = [];
foreach ($this->assetMapper->allAssets() as $asset) {
if (preg_match($this->workbox->fontCache->regex, $asset->sourcePath) === 1) {
if (preg_match($this->workbox->fontCache->regex, $asset->publicPath) === 1) {
$fonts[] = $asset->publicPath;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/CachingStrategy/PreloadUrlsGeneratorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use SpomkyLabs\PwaBundle\Service\CanLogInterface;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use function array_key_exists;
use function sprintf;

Expand All @@ -25,7 +25,7 @@ final class PreloadUrlsGeneratorManager implements CanLogInterface
* @param PreloadUrlsGeneratorInterface[] $generators
*/
public function __construct(
#[TaggedIterator('spomky_labs_pwa.preload_urls_generator')]
#[AutowireIterator('spomky_labs_pwa.preload_urls_generator')]
iterable $generators
) {
$this->logger = new NullLogger();
Expand Down
4 changes: 2 additions & 2 deletions src/CachingStrategy/ResourceCaches.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use SpomkyLabs\PwaBundle\WorkboxPlugin\ExpirationPlugin;
use SpomkyLabs\PwaBundle\WorkboxPlugin\RangeRequestsPlugin;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use Symfony\Component\Serializer\Encoder\JsonEncode;
use Symfony\Component\Serializer\SerializerInterface;
use function count;
Expand All @@ -41,7 +41,7 @@ public function __construct(
private readonly PreloadUrlsGeneratorManager $preloadUrlsGeneratorManager,
ServiceWorker $serviceWorker,
private readonly SerializerInterface $serializer,
#[TaggedIterator('spomky_labs_pwa.match_callback_handler')]
#[AutowireIterator('spomky_labs_pwa.match_callback_handler')]
private readonly iterable $matchCallbackHandlers,
#[Autowire(param: 'kernel.debug')]
bool $debug,
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ListCacheStrategiesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use Symfony\Component\Yaml\Yaml;
use function count;

Expand All @@ -25,7 +25,7 @@ final class ListCacheStrategiesCommand extends Command
* @param iterable<HasCacheStrategiesInterface> $services
*/
public function __construct(
#[TaggedIterator('spomky_labs_pwa.cache_strategy')]
#[AutowireIterator('spomky_labs_pwa.cache_strategy')]
private readonly iterable $services,
) {
parent::__construct();
Expand Down
6 changes: 3 additions & 3 deletions src/DataCollector/PwaCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use SpomkyLabs\PwaBundle\Service\FaviconsCompiler;
use SpomkyLabs\PwaBundle\Service\ManifestCompiler;
use SpomkyLabs\PwaBundle\Service\ServiceWorkerCompiler;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
Expand All @@ -37,7 +37,7 @@ final class PwaCollector extends DataCollector
*/
public function __construct(
private readonly SerializerInterface $serializer,
#[TaggedIterator('spomky_labs_pwa.cache_strategy')]
#[AutowireIterator('spomky_labs_pwa.cache_strategy')]
private readonly iterable $cachingServices,
private readonly Manifest $manifest,
private readonly ServiceWorker $serviceWorker,
Expand All @@ -48,7 +48,7 @@ public function __construct(
) {
}

public function collect(Request $request, Response $response, Throwable $exception = null): void
public function collect(Request $request, Response $response, ?Throwable $exception = null): void
{
$jsonOptions = [
AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true,
Expand Down
16 changes: 8 additions & 8 deletions src/Normalizer/AssetNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,37 @@ public function __construct(
/**
* @return array{src: string, sizes?: string, form_factor?: string, label?: string, platform?: string, format?: string}
*/
public function normalize(mixed $object, string $format = null, array $context = []): string
public function normalize(mixed $data, ?string $format = null, array $context = []): string
{
assert($object instanceof Asset);
assert($data instanceof Asset);
$url = null;
if (! str_starts_with($object->src, '/')) {
$asset = $this->assetMapper->getAsset($object->src);
if (! str_starts_with($data->src, '/')) {
$asset = $this->assetMapper->getAsset($data->src);
$url = $asset?->publicPath;
}
if ($url === null) {
$url = $object->src;
$url = $data->src;
}

return $url;
}

public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
{
assert(is_string($data));

return Asset::create($data);
}

public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof Asset;
}

public function supportsDenormalization(
mixed $data,
string $type,
string $format = null,
?string $format = null,
array $context = []
): bool {
return $type === Asset::class;
Expand Down
14 changes: 7 additions & 7 deletions src/Normalizer/IconNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public function __construct(
/**
* @return array{src: string, sizes?: string, type?: string, purpose?: string}
*/
public function normalize(mixed $object, string $format = null, array $context = []): array
public function normalize(mixed $data, ?string $format = null, array $context = []): array
{
assert($object instanceof Icon);
$icon = $this->iconResolver->getIcon($object);
$imageType = $this->iconResolver->getType($object->type, $icon->url);
assert($data instanceof Icon);
$icon = $this->iconResolver->getIcon($data);
$imageType = $this->iconResolver->getType($data->type, $icon->url);

$result = [
'src' => $icon->url,
'sizes' => $object->getSizeList(),
'sizes' => $data->getSizeList(),
'type' => $imageType,
'purpose' => $object->purpose,
'purpose' => $data->purpose,
];

$cleanup = static fn (array $data): array => array_filter(
Expand All @@ -44,7 +44,7 @@ public function normalize(mixed $object, string $format = null, array $context =
return $cleanup($result);
}

public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof Icon;
}
Expand Down
20 changes: 10 additions & 10 deletions src/Normalizer/ScreenshotNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ public function __construct(
/**
* @return array{src: string, sizes?: string, form_factor?: string, label?: string, platform?: string, format?: string}
*/
public function normalize(mixed $object, string $format = null, array $context = []): array
public function normalize(mixed $data, ?string $format = null, array $context = []): array
{
assert($object instanceof Screenshot);
assert($data instanceof Screenshot);
$asset = null;
$imageType = $object->type;
if ($imageType === null && ! str_starts_with($object->src->src, '/')) {
$asset = $this->assetMapper->getAsset($object->src->src);
$imageType = $data->type;
if ($imageType === null && ! str_starts_with($data->src->src, '/')) {
$asset = $this->assetMapper->getAsset($data->src->src);
$imageType = $this->getType($asset);
}
['sizes' => $sizes, 'formFactor' => $formFactor] = $this->getSizes($object, $asset);
['sizes' => $sizes, 'formFactor' => $formFactor] = $this->getSizes($data, $asset);

$result = [
'src' => $this->normalizer->normalize($object->src, $format, $context),
'src' => $this->normalizer->normalize($data->src, $format, $context),
'sizes' => $sizes,
'form_factor' => $formFactor,
'label' => $object->label,
'platform' => $object->platform,
'label' => $data->label,
'platform' => $data->platform,
'format' => $imageType,
];

Expand All @@ -55,7 +55,7 @@ public function normalize(mixed $object, string $format = null, array $context =
return $cleanup($result);
}

public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof Screenshot;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Normalizer/ServiceWorkerNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
/**
* @return array{scope?: string, src: string, use_cache?: bool}
*/
public function normalize(mixed $object, string $format = null, array $context = []): array
public function normalize(mixed $data, ?string $format = null, array $context = []): array
{
assert($object instanceof ServiceWorker);
assert($data instanceof ServiceWorker);

$result = [
'src' => '/' . trim($object->dest, '/'),
'scope' => $object->scope,
'use_cache' => $object->useCache,
'src' => '/' . trim($data->dest, '/'),
'scope' => $data->scope,
'use_cache' => $data->useCache,
];

$cleanup = static fn (array $data): array => array_filter(
Expand All @@ -30,7 +30,7 @@ public function normalize(mixed $object, string $format = null, array $context =
return $cleanup($result);
}

public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof ServiceWorker;
}
Expand Down
16 changes: 8 additions & 8 deletions src/Normalizer/UrlNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ public function __construct(
) {
}

public function normalize(mixed $object, string $format = null, array $context = []): string
public function normalize(mixed $data, ?string $format = null, array $context = []): string
{
assert($object instanceof Url);
assert($data instanceof Url);

// If the path is a valid URL, we return it directly
if (str_starts_with($object->path, '/') && filter_var($object->path, FILTER_VALIDATE_URL) !== false) {
return $object->path;
if (str_starts_with($data->path, '/') && filter_var($data->path, FILTER_VALIDATE_URL) !== false) {
return $data->path;
}

// If the path is an asset, we return the public path
$asset = $this->assetMapper->getAsset($object->path);
$asset = $this->assetMapper->getAsset($data->path);
if ($asset !== null) {
return $asset->publicPath;
}

// Otherwise, we try to generate the URL
try {
return $this->router->generate($object->path, $object->params, $object->pathTypeReference);
return $this->router->generate($data->path, $data->params, $data->pathTypeReference);
} catch (Throwable) {
// If the URL cannot be generated, we return the path as is
return $object->path;
return $data->path;
}
}

public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof Url;
}
Expand Down
Loading

0 comments on commit 33291c5

Please sign in to comment.