-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
When passing a (class) constant to the get function of the container, it's impossible to derive a class from it, so we add a type hint to the variable.
But apparently PHPStan (in conjunction with your package) thinks that the value of the constant is a class and complains that the manually added type is not a subtype of it.
E.g.:
<?php
declare(strict_types=1);
use Psr\Container\ContainerInterface;
final readonly class SomeServiceFactory
{
private const string TAX_RATE = 'TaxRate';
public function __invoke(ContainerInterface $container): SomeService
{
/** @var float $taxRate */
$taxRate = $container->get(self::TAX_RATE);
return new SomeService($taxRate);
}
}
PHPStan emits the error PHPDoc tag @var with type float is not subtype of type TaxRate..
Instead, if I use the string literal directly ($container->get('TaxRate')), there are no errors.
Thanks for your help!
Metadata
Metadata
Assignees
Labels
No labels