Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thePanz opened this issue Feb 21, 2024 · 5 comments
Closed

Comments

@thePanz
Copy link
Contributor

thePanz commented Feb 21, 2024

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

@ondrejmirtes
Copy link
Member

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
Copy link
Contributor Author

thePanz commented Feb 21, 2024

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

Anyhow:

WDYT?

@ondrejmirtes
Copy link
Member

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
Copy link
Contributor Author

thePanz commented Feb 23, 2024

should we re-introduce the documentation

Yeah, sure

I created a PR here: #382

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants