<?php
declare(strict_types=1);
namespace App\DependencyInjection\Compiler;
use Faker\Generator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
final class AddCustomFakerGeneratorProvidersPass implements CompilerPassInterface
{
public const TAG = 'app.faker.generator_provider';
public function process(ContainerBuilder $container): void
{
if (!$container->has(Generator::class)) {
return;
}
$svc = $container->findDefinition(Generator::class);
$taggedDeps = $container->findTaggedServiceIds(self::TAG);
foreach ($taggedDeps as $id => $tags) {
$svc->addMethodCall('addProvider', [new Reference($id)]);
}
}
}
PHPStan with Symfony extension reports that has() will always return true:
I have a simple compiler pass like below:
PHPStan with Symfony extension reports that
has()
will always return true:This is taken straight from Symfony docs at https://symfony.com/doc/current/service_container/tags.html#create-a-compiler-pass and they even add a separate warning stating "// always first check if the primary service is defined". Thus, I think this is a bug in PHPStan Symfony extension.
Here's my full PHPStan config: