phpstan / phpstan-symfony

Symfony extension for PHPStan
MIT License
698 stars 89 forks source link

PHPstan does not find container helper functions used on packages php configs #381

Closed thePanz closed 6 months ago

thePanz commented 6 months ago

Similar (but solved) issue: https://github.com/phpstan/phpstan-symfony/issues/269 , where the helper functions are used in the services.php file.

In this issue, the error is triggered when helper functions are used in a package configuration file (the ones under config/packages/**.php).

Example:

# config/packages/messenger.php
<?php

declare(strict_types=1);

use App\Infrastructure\Symfony\Messenger\AsyncMessage;
use Symfony\Config\FrameworkConfig;

use function Symfony\Component\DependencyInjection\Loader\Configurator\env;

return static function (FrameworkConfig $framework): void {
    $messenger = $framework->messenger()->failureTransport('failed');
    $messenger->transport('async')->dsn(env('MESSENGER_TRANSPORT_DSN'));
}:

Phpstan error:

Used function Symfony\Component\DependencyInjection\Loader\Configurator\env not found

The solution is to re-add the scanFile configuration to phpstan.neon, as initially documented in https://github.com/phpstan/phpstan-symfony/pull/271

Note: that the documentation was added in b1c5152, but then removed in 94e6c34

ondrejmirtes commented 6 months ago

This is not PHPStan's fault, but Symfony's. These functions aren't discoverable by the autoloader. The root issue should be fixed in the framework.

thePanz commented 6 months ago

Thanks @ondrejmirtes , I agree that it is a SF issue :+1:

Anyhow:

WDYT?

ondrejmirtes commented 6 months ago

how was it solved

See the release notes for PHPStan 1.6.6: https://github.com/phpstan/phpstan/releases/tag/1.6.6

should we re-introduce the documentation

Yeah, sure

thePanz commented 6 months ago

should we re-introduce the documentation

Yeah, sure

I created a PR here: https://github.com/phpstan/phpstan-symfony/pull/382

github-actions[bot] commented 5 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.