Skip to content

Commit

Permalink
Replace TaggedIterator with AutowireIterator across multiple files (#222
Browse files Browse the repository at this point in the history
)

* Replace TaggedIterator with AutowireIterator across multiple files

The commit switches the usage from TaggedIterator to AutowireIterator to better manage dependencies within the application. This affects multiple classes in src directory involving spomky_labs_pwa cache strategy, match callback handlers, and other related dependencies. The change enhances dependency handling and supports cleaner code injection.
  • Loading branch information
Spomky authored Jul 13, 2024
1 parent 65c2a87 commit a7d00ca
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 68 deletions.
9 changes: 5 additions & 4 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 @@ -58,13 +59,13 @@
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-beberlei-assert": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan-strict-rules": "^1.0",
"phpstan/phpstan-symfony": "^1.3",
"phpstan/phpstan-symfony": "^1.4",
"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",
"staabm/phpstan-todo-by": "^0.1.27",
"struggle-for-php/sfp-phpstan-psr-log": "^0.21.0",
"symfony/filesystem": "^6.4|^7.0",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/mime": "^6.4|^7.0",
Expand Down
62 changes: 16 additions & 46 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ parameters:
count: 1
path: src/CachingStrategy/AssetCache.php

-
message: "#^Attribute class Symfony\\\\Component\\\\DependencyInjection\\\\Attribute\\\\TaggedIterator is deprecated\\: since Symfony 7\\.1, use \\{@see AutowireIterator\\} instead\\.$#"
count: 1
path: src/CachingStrategy/BackgroundSync.php

-
message: "#^Only iterables can be unpacked, mixed given in argument \\#1\\.$#"
count: 1
Expand All @@ -40,16 +35,6 @@ parameters:
count: 2
path: src/CachingStrategy/FontCache.php

-
message: "#^Attribute class Symfony\\\\Component\\\\DependencyInjection\\\\Attribute\\\\TaggedIterator is deprecated\\: since Symfony 7\\.1, use \\{@see AutowireIterator\\} instead\\.$#"
count: 1
path: src/CachingStrategy/PreloadUrlsGeneratorManager.php

-
message: "#^Attribute class Symfony\\\\Component\\\\DependencyInjection\\\\Attribute\\\\TaggedIterator is deprecated\\: since Symfony 7\\.1, use \\{@see AutowireIterator\\} instead\\.$#"
count: 1
path: src/CachingStrategy/ResourceCaches.php

-
message: "#^Only iterables can be unpacked, mixed given in argument \\#1\\.$#"
count: 1
Expand Down Expand Up @@ -135,16 +120,6 @@ parameters:
count: 1
path: src/Command/CreateScreenshotCommand.php

-
message: "#^Attribute class Symfony\\\\Component\\\\DependencyInjection\\\\Attribute\\\\TaggedIterator is deprecated\\: since Symfony 7\\.1, use \\{@see AutowireIterator\\} instead\\.$#"
count: 1
path: src/Command/ListCacheStrategiesCommand.php

-
message: "#^Attribute class Symfony\\\\Component\\\\DependencyInjection\\\\Attribute\\\\TaggedIterator is deprecated\\: since Symfony 7\\.1, use \\{@see AutowireIterator\\} instead\\.$#"
count: 1
path: src/DataCollector/PwaCollector.php

-
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\BackgroundSync has an uninitialized property \\$forceSyncFallback\\. Give it default value or assign it in the constructor\\.$#"
count: 1
Expand Down Expand Up @@ -430,6 +405,21 @@ parameters:
count: 1
path: src/ImageProcessor/GDImageProcessor.php

-
message: "#^Parameter \\#2 \\$red of function imagecolorallocate expects int\\<0, 255\\>, int given\\.$#"
count: 1
path: src/ImageProcessor/GDImageProcessor.php

-
message: "#^Parameter \\#3 \\$green of function imagecolorallocate expects int\\<0, 255\\>, int given\\.$#"
count: 1
path: src/ImageProcessor/GDImageProcessor.php

-
message: "#^Parameter \\#4 \\$blue of function imagecolorallocate expects int\\<0, 255\\>, int given\\.$#"
count: 1
path: src/ImageProcessor/GDImageProcessor.php

-
message: "#^Should not use node with type \"Stmt_Echo\", please change the code\\.$#"
count: 3
Expand Down Expand Up @@ -605,16 +595,6 @@ parameters:
count: 1
path: src/Service/FaviconsCompiler.php

-
message: "#^Attribute class Symfony\\\\Component\\\\DependencyInjection\\\\Attribute\\\\TaggedIterator is deprecated\\: since Symfony 7\\.1, use \\{@see AutowireIterator\\} instead\\.$#"
count: 1
path: src/Service/ServiceWorkerCompiler.php

-
message: "#^Attribute class Symfony\\\\Component\\\\DependencyInjection\\\\Attribute\\\\TaggedIterator is deprecated\\: since Symfony 7\\.1, use \\{@see AutowireIterator\\} instead\\.$#"
count: 1
path: src/ServiceWorkerRule/AppendCacheStrategies.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
count: 1
Expand All @@ -628,14 +608,4 @@ parameters:
-
message: "#^Method SpomkyLabs\\\\PwaBundle\\\\SpomkyLabsPwaBundle\\:\\:loadExtension\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#"
count: 1
path: src/SpomkyLabsPwaBundle.php

-
message: "#^Attribute class Symfony\\\\Component\\\\DependencyInjection\\\\Attribute\\\\TaggedIterator is deprecated\\: since Symfony 7\\.1, use \\{@see AutowireIterator\\} instead\\.$#"
count: 1
path: src/Subscriber/FileCompileEventListener.php

-
message: "#^Attribute class Symfony\\\\Component\\\\DependencyInjection\\\\Attribute\\\\TaggedIterator is deprecated\\: since Symfony 7\\.1, use \\{@see AutowireIterator\\} instead\\.$#"
count: 1
path: src/Subscriber/PwaDevServerSubscriber.php
path: src/SpomkyLabsPwaBundle.php
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
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;

final class PreloadUrlsGeneratorManager implements CanLogInterface
Expand All @@ -24,7 +24,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 @@ -40,7 +40,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('%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
4 changes: 2 additions & 2 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 Down
4 changes: 2 additions & 2 deletions src/Service/ServiceWorkerCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Symfony\Component\AssetMapper\AssetMapperInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use function assert;
use function count;
use function in_array;
Expand All @@ -34,7 +34,7 @@ final class ServiceWorkerCompiler implements FileCompilerInterface, CanLogInterf
public function __construct(
private readonly ServiceWorker $serviceWorker,
private readonly AssetMapperInterface $assetMapper,
#[TaggedIterator('spomky_labs_pwa.service_worker_rule', defaultPriorityMethod: 'getPriority')]
#[AutowireIterator('spomky_labs_pwa.service_worker_rule', defaultPriorityMethod: 'getPriority')]
private readonly iterable $serviceworkerRules,
#[Autowire('%kernel.debug%')]
public readonly bool $debug,
Expand Down
4 changes: 2 additions & 2 deletions src/ServiceWorkerRule/AppendCacheStrategies.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use SpomkyLabs\PwaBundle\CachingStrategy\HasCacheStrategiesInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use const PHP_EOL;

final readonly class AppendCacheStrategies implements ServiceWorkerRuleInterface
Expand All @@ -15,7 +15,7 @@
* @param iterable<HasCacheStrategiesInterface> $cacheStrategies
*/
public function __construct(
#[TaggedIterator('spomky_labs_pwa.cache_strategy')]
#[AutowireIterator('spomky_labs_pwa.cache_strategy')]
private iterable $cacheStrategies,
#[Autowire('%kernel.debug%')]
public bool $debug,
Expand Down
4 changes: 2 additions & 2 deletions src/Subscriber/FileCompileEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Symfony\Component\AssetMapper\Event\PreAssetsCompileEvent;
use Symfony\Component\AssetMapper\Path\PublicAssetsFilesystemInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener(PreAssetsCompileEvent::class)]
Expand All @@ -23,7 +23,7 @@ final class FileCompileEventListener implements CanLogInterface
* @param iterable<FileCompilerInterface> $fileCompilers
*/
public function __construct(
#[TaggedIterator('spomky_labs_pwa.compiler')]
#[AutowireIterator('spomky_labs_pwa.compiler')]
private readonly iterable $fileCompilers,
#[Autowire('@asset_mapper.local_public_assets_filesystem')]
private readonly PublicAssetsFilesystemInterface $assetsFilesystem,
Expand Down
4 changes: 2 additions & 2 deletions src/Subscriber/PwaDevServerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SpomkyLabs\PwaBundle\Service\CanLogInterface;
use SpomkyLabs\PwaBundle\Service\Data;
use SpomkyLabs\PwaBundle\Service\FileCompilerInterface;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\RequestEvent;
Expand All @@ -25,7 +25,7 @@ final class PwaDevServerSubscriber implements EventSubscriberInterface, CanLogIn
* @param iterable<FileCompilerInterface> $fileCompilers
*/
public function __construct(
#[TaggedIterator('spomky_labs_pwa.compiler')]
#[AutowireIterator('spomky_labs_pwa.compiler')]
private readonly iterable $fileCompilers,
private readonly null|Profiler $profiler,
) {
Expand Down
3 changes: 3 additions & 0 deletions tests/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
'secret' => 'test',
'http_method_override' => true,
'handle_all_throwables' => true,
'assets' => [
'enabled' => true,
],
'session' => [
'storage_factory_id' => 'session.storage.factory.mock_file',
'cookie_secure' => 'auto',
Expand Down

0 comments on commit a7d00ca

Please sign in to comment.