Skip to content

Commit

Permalink
Naming convention for interfaces (#155)
Browse files Browse the repository at this point in the history
Interfaces now have an `Interface` suffix as per https://www.php-fig.org/bylaws/psr-naming-conventions/
  • Loading branch information
Spomky authored Apr 4, 2024
1 parent 0e5285b commit 2ecc4e3
Show file tree
Hide file tree
Showing 49 changed files with 200 additions and 128 deletions.
12 changes: 6 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ parameters:
path: src/Command/CreateIconsCommand.php

-
message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessor\\:\\:process\\(\\) expects string, string\\|false given\\.$#"
message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessorInterface\\:\\:process\\(\\) expects string, string\\|false given\\.$#"
count: 1
path: src/Command/CreateIconsCommand.php

Expand All @@ -91,7 +91,7 @@ parameters:
path: src/Command/CreateIconsCommand.php

-
message: "#^Parameter \\#4 \\$format of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessor\\:\\:process\\(\\) expects string\\|null, mixed given\\.$#"
message: "#^Parameter \\#4 \\$format of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessorInterface\\:\\:process\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/Command/CreateIconsCommand.php

Expand All @@ -111,12 +111,12 @@ parameters:
path: src/Command/CreateScreenshotCommand.php

-
message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessor\\:\\:getSizes\\(\\) expects string, string\\|false given\\.$#"
message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessorInterface\\:\\:getSizes\\(\\) expects string, string\\|false given\\.$#"
count: 1
path: src/Command/CreateScreenshotCommand.php

-
message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessor\\:\\:process\\(\\) expects string, string\\|false given\\.$#"
message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessorInterface\\:\\:process\\(\\) expects string, string\\|false given\\.$#"
count: 1
path: src/Command/CreateScreenshotCommand.php

Expand All @@ -136,7 +136,7 @@ parameters:
path: src/Command/CreateScreenshotCommand.php

-
message: "#^Parameter \\#4 \\$format of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessor\\:\\:process\\(\\) expects string\\|null, mixed given\\.$#"
message: "#^Parameter \\#4 \\$format of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessorInterface\\:\\:process\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/Command/CreateScreenshotCommand.php

Expand Down Expand Up @@ -501,7 +501,7 @@ parameters:
path: src/Normalizer/ScreenshotNormalizer.php

-
message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessor\\:\\:getSizes\\(\\) expects string, string\\|false given\\.$#"
message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessorInterface\\:\\:getSizes\\(\\) expects string, string\\|false given\\.$#"
count: 1
path: src/Normalizer/ScreenshotNormalizer.php

Expand Down
4 changes: 2 additions & 2 deletions src/CachingStrategy/AssetCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use const JSON_UNESCAPED_SLASHES;
use const JSON_UNESCAPED_UNICODE;

final readonly class AssetCache implements HasCacheStrategies
final readonly class AssetCache implements HasCacheStrategiesInterface
{
private int $jsonOptions;

Expand Down Expand Up @@ -53,7 +53,7 @@ public function getCacheStrategies(): array
$strategy = WorkboxCacheStrategy::create(
$this->workbox->enabled && $this->workbox->assetCache->enabled,
true,
CacheStrategy::STRATEGY_CACHE_FIRST,
CacheStrategyInterface::STRATEGY_CACHE_FIRST,
sprintf("({url}) => url.pathname.startsWith('%s')", $this->assetPublicPrefix),
)
->withName($this->workbox->assetCache->cacheName)
Expand Down
10 changes: 5 additions & 5 deletions src/CachingStrategy/BackgroundSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

use SpomkyLabs\PwaBundle\Dto\ServiceWorker;
use SpomkyLabs\PwaBundle\Dto\Workbox;
use SpomkyLabs\PwaBundle\MatchCallbackHandler\MatchCallbackHandler;
use SpomkyLabs\PwaBundle\MatchCallbackHandler\MatchCallbackHandlerInterface;
use SpomkyLabs\PwaBundle\WorkboxPlugin\BackgroundSyncPlugin;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;

final readonly class BackgroundSync implements HasCacheStrategies
final readonly class BackgroundSync implements HasCacheStrategiesInterface
{
private Workbox $workbox;

/**
* @param iterable<MatchCallbackHandler> $matchCallbackHandlers
* @param iterable<MatchCallbackHandlerInterface> $matchCallbackHandlers
*/
public function __construct(
ServiceWorker $serviceWorker,
Expand All @@ -26,7 +26,7 @@ public function __construct(
}

/**
* @return array<CacheStrategy>
* @return array<CacheStrategyInterface>
*/
public function getCacheStrategies(): array
{
Expand All @@ -35,7 +35,7 @@ public function getCacheStrategies(): array
$strategies[] = WorkboxCacheStrategy::create(
$this->workbox->enabled,
true,
CacheStrategy::STRATEGY_NETWORK_ONLY,
CacheStrategyInterface::STRATEGY_NETWORK_ONLY,
$this->prepareMatchCallback($sync->matchCallback)
)
->withName('Background Sync')
Expand Down
30 changes: 4 additions & 26 deletions src/CachingStrategy/CacheStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,9 @@

namespace SpomkyLabs\PwaBundle\CachingStrategy;

interface CacheStrategy
/**
* @deprecated since 1.2.0, will be removed in 2.0.0. Use CacheStrategyInterface instead.
*/
interface CacheStrategy extends CacheStrategyInterface
{
public const STRATEGY_CACHE_FIRST = 'CacheFirst';

public const STRATEGY_CACHE_ONLY = 'CacheOnly';

public const STRATEGY_NETWORK_FIRST = 'NetworkFirst';

public const STRATEGY_NETWORK_ONLY = 'NetworkOnly';

public const STRATEGY_STALE_WHILE_REVALIDATE = 'StaleWhileRevalidate';

public const STRATEGIES = [
self::STRATEGY_CACHE_FIRST,
self::STRATEGY_CACHE_ONLY,
self::STRATEGY_NETWORK_FIRST,
self::STRATEGY_NETWORK_ONLY,
self::STRATEGY_STALE_WHILE_REVALIDATE,
];

public function getName(): ?string;

public function isEnabled(): bool;

public function needsWorkbox(): bool;

public function render(string $cacheObjectName, bool $debug = false): string;
}
34 changes: 34 additions & 0 deletions src/CachingStrategy/CacheStrategyInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace SpomkyLabs\PwaBundle\CachingStrategy;

interface CacheStrategyInterface
{
public const STRATEGY_CACHE_FIRST = 'CacheFirst';

public const STRATEGY_CACHE_ONLY = 'CacheOnly';

public const STRATEGY_NETWORK_FIRST = 'NetworkFirst';

public const STRATEGY_NETWORK_ONLY = 'NetworkOnly';

public const STRATEGY_STALE_WHILE_REVALIDATE = 'StaleWhileRevalidate';

public const STRATEGIES = [
self::STRATEGY_CACHE_FIRST,
self::STRATEGY_CACHE_ONLY,
self::STRATEGY_NETWORK_FIRST,
self::STRATEGY_NETWORK_ONLY,
self::STRATEGY_STALE_WHILE_REVALIDATE,
];

public function getName(): ?string;

public function isEnabled(): bool;

public function needsWorkbox(): bool;

public function render(string $cacheObjectName, bool $debug = false): string;
}
4 changes: 2 additions & 2 deletions src/CachingStrategy/FontCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use const JSON_UNESCAPED_SLASHES;
use const JSON_UNESCAPED_UNICODE;

final readonly class FontCache implements HasCacheStrategies
final readonly class FontCache implements HasCacheStrategiesInterface
{
private int $jsonOptions;

Expand Down Expand Up @@ -49,7 +49,7 @@ public function getCacheStrategies(): array
$strategy = WorkboxCacheStrategy::create(
$this->workbox->enabled && $this->workbox->fontCache->enabled,
true,
CacheStrategy::STRATEGY_CACHE_FIRST,
CacheStrategyInterface::STRATEGY_CACHE_FIRST,
"({request}) => request.destination === 'font'"
)
->withName($this->workbox->fontCache->cacheName ?? 'fonts')
Expand Down
6 changes: 3 additions & 3 deletions src/CachingStrategy/GoogleFontCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SpomkyLabs\PwaBundle\WorkboxPlugin\CacheableResponsePlugin;
use SpomkyLabs\PwaBundle\WorkboxPlugin\ExpirationPlugin;

final readonly class GoogleFontCache implements HasCacheStrategies
final readonly class GoogleFontCache implements HasCacheStrategiesInterface
{
private Workbox $workbox;

Expand All @@ -30,14 +30,14 @@ public function getCacheStrategies(): array
WorkboxCacheStrategy::create(
$this->workbox->enabled && $this->workbox->googleFontCache->enabled,
true,
CacheStrategy::STRATEGY_STALE_WHILE_REVALIDATE,
CacheStrategyInterface::STRATEGY_STALE_WHILE_REVALIDATE,
"({url}) => url.origin === 'https://fonts.googleapis.com'",
)
->withName($prefix . 'google-fonts-stylesheets'),
WorkboxCacheStrategy::create(
$this->workbox->enabled && $this->workbox->googleFontCache->enabled,
true,
CacheStrategy::STRATEGY_CACHE_FIRST,
CacheStrategyInterface::STRATEGY_CACHE_FIRST,
"({url}) => url.origin === 'https://fonts.gstatic.com'"
)
->withName($prefix . 'google-fonts-webfonts')
Expand Down
9 changes: 4 additions & 5 deletions src/CachingStrategy/HasCacheStrategies.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace SpomkyLabs\PwaBundle\CachingStrategy;

interface HasCacheStrategies
/**
* @deprecated since 1.2.0, will be removed in 2.0.0. Use HasCacheStrategiesInterface instead.
*/
interface HasCacheStrategies extends HasCacheStrategiesInterface
{
/**
* @return array<CacheStrategy>
*/
public function getCacheStrategies(): array;
}
13 changes: 13 additions & 0 deletions src/CachingStrategy/HasCacheStrategiesInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace SpomkyLabs\PwaBundle\CachingStrategy;

interface HasCacheStrategiesInterface
{
/**
* @return array<CacheStrategyInterface>
*/
public function getCacheStrategies(): array;
}
4 changes: 2 additions & 2 deletions src/CachingStrategy/ImageCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\AssetMapper\Path\PublicAssetsPathResolverInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

final readonly class ImageCache implements HasCacheStrategies
final readonly class ImageCache implements HasCacheStrategiesInterface
{
private string $assetPublicPrefix;

Expand All @@ -30,7 +30,7 @@ public function getCacheStrategies(): array
WorkboxCacheStrategy::create(
$this->workbox->enabled && $this->workbox->imageCache->enabled,
true,
CacheStrategy::STRATEGY_CACHE_FIRST,
CacheStrategyInterface::STRATEGY_CACHE_FIRST,
sprintf(
"({request, url}) => (request.destination === 'image' && !url.pathname.startsWith('%s'))",
$this->assetPublicPrefix
Expand Down
4 changes: 2 additions & 2 deletions src/CachingStrategy/ManifestCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use SpomkyLabs\PwaBundle\Dto\Workbox;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

final readonly class ManifestCache implements HasCacheStrategies
final readonly class ManifestCache implements HasCacheStrategiesInterface
{
private string $manifestPublicUrl;

Expand All @@ -29,7 +29,7 @@ public function getCacheStrategies(): array
WorkboxCacheStrategy::create(
$this->workbox->enabled && $this->workbox->cacheManifest,
true,
CacheStrategy::STRATEGY_STALE_WHILE_REVALIDATE,
CacheStrategyInterface::STRATEGY_STALE_WHILE_REVALIDATE,
sprintf("({url}) => '%s' === url.pathname", $this->manifestPublicUrl),
)
->withName('manifest'),
Expand Down
10 changes: 5 additions & 5 deletions src/CachingStrategy/ResourceCaches.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use SpomkyLabs\PwaBundle\Dto\ServiceWorker;
use SpomkyLabs\PwaBundle\Dto\Workbox;
use SpomkyLabs\PwaBundle\MatchCallbackHandler\MatchCallbackHandler;
use SpomkyLabs\PwaBundle\MatchCallbackHandler\MatchCallbackHandlerInterface;
use SpomkyLabs\PwaBundle\WorkboxPlugin\BroadcastUpdatePlugin;
use SpomkyLabs\PwaBundle\WorkboxPlugin\CacheableResponsePlugin;
use SpomkyLabs\PwaBundle\WorkboxPlugin\ExpirationPlugin;
Expand All @@ -21,14 +21,14 @@
use const JSON_UNESCAPED_SLASHES;
use const JSON_UNESCAPED_UNICODE;

final readonly class ResourceCaches implements HasCacheStrategies
final readonly class ResourceCaches implements HasCacheStrategiesInterface
{
private int $jsonOptions;

private Workbox $workbox;

/**
* @param iterable<MatchCallbackHandler> $matchCallbackHandlers
* @param iterable<MatchCallbackHandlerInterface> $matchCallbackHandlers
*/
public function __construct(
ServiceWorker $serviceWorker,
Expand Down Expand Up @@ -63,10 +63,10 @@ public function getCacheStrategies(): array
$resourceCache->cacheableResponseHeaders
),
];
if ($resourceCache->broadcast === true && $resourceCache->strategy === CacheStrategy::STRATEGY_STALE_WHILE_REVALIDATE) {
if ($resourceCache->broadcast === true && $resourceCache->strategy === CacheStrategyInterface::STRATEGY_STALE_WHILE_REVALIDATE) {
$plugins[] = BroadcastUpdatePlugin::create($resourceCache->broadcastHeaders);
}
if ($resourceCache->rangeRequests === true && $resourceCache->strategy !== CacheStrategy::STRATEGY_NETWORK_ONLY) {
if ($resourceCache->rangeRequests === true && $resourceCache->strategy !== CacheStrategyInterface::STRATEGY_NETWORK_ONLY) {
$plugins[] = RangeRequestsPlugin::create();
}
if ($resourceCache->maxEntries !== null || $resourceCache->maxAgeInSeconds() !== null) {
Expand Down
12 changes: 6 additions & 6 deletions src/CachingStrategy/WorkboxCacheStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

namespace SpomkyLabs\PwaBundle\CachingStrategy;

use SpomkyLabs\PwaBundle\WorkboxPlugin\CachePlugin;
use SpomkyLabs\PwaBundle\WorkboxPlugin\CachePluginInterface;
use function in_array;
use const JSON_PRETTY_PRINT;
use const JSON_THROW_ON_ERROR;
use const JSON_UNESCAPED_SLASHES;
use const JSON_UNESCAPED_UNICODE;

final class WorkboxCacheStrategy implements CacheStrategy
final class WorkboxCacheStrategy implements CacheStrategyInterface
{
private null|string $name = null;

private null|string $method = null;

/**
* @var array<CachePlugin>
* @var array<CachePluginInterface>
*/
private array $plugins = [];

Expand Down Expand Up @@ -63,7 +63,7 @@ public function withMethod(string $method): static
return $this;
}

public function withPlugin(CachePlugin $plugin, CachePlugin ...$plugins): static
public function withPlugin(CachePluginInterface $plugin, CachePluginInterface ...$plugins): static
{
$this->plugins = array_merge([$plugin], $plugins);
return $this;
Expand Down Expand Up @@ -122,7 +122,7 @@ public function render(string $cacheObjectName, bool $debug = false): string
$cacheName = sprintf("cacheName: '%s',", $this->getName() ?? $cacheObjectName);
}
$plugins = sprintf('[%s]', implode(', ', array_map(
fn (CachePlugin $plugin) => $plugin->render($jsonOptions),
fn (CachePluginInterface $plugin) => $plugin->render($jsonOptions),
$this->plugins
)));
$method = $this->method !== null ? ",'{$this->method}'" : '';
Expand Down Expand Up @@ -191,7 +191,7 @@ public function getMethod(): ?string
}

/**
* @return array<CachePlugin>
* @return array<CachePluginInterface>
*/
public function getPlugins(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Command/CreateIconsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SpomkyLabs\PwaBundle\Command;

use SpomkyLabs\PwaBundle\ImageProcessor\ImageProcessor;
use SpomkyLabs\PwaBundle\ImageProcessor\ImageProcessorInterface;
use Symfony\Component\AssetMapper\AssetMapperInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand All @@ -28,7 +28,7 @@ public function __construct(
private readonly Filesystem $filesystem,
#[Autowire('%kernel.project_dir%')]
private readonly string $projectDir,
private readonly null|ImageProcessor $imageProcessor,
private readonly null|ImageProcessorInterface $imageProcessor,
) {
parent::__construct();
}
Expand Down
Loading

0 comments on commit 2ecc4e3

Please sign in to comment.