phpstan/phpstan-symfony

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

thePanz opened this issue · 5 comments

Similar (but solved) issue: #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 #271

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

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.

Thanks @ondrejmirtes , I agree that it is a SF issue 👍

Anyhow:

  • how was it solved in #269 (comment) ?
  • should we re-introduce the documentation in the readme, thus restore commit b1c5152? this would help other developers to solve the problem

WDYT?

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

should we re-introduce the documentation

Yeah, sure

I created a PR here: #382

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.