Skip to content
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

Symfony's Configurator functions env() and param() not found #292

Closed
ThomasLandauer opened this issue Dec 10, 2022 · 4 comments
Closed

Symfony's Configurator functions env() and param() not found #292

ThomasLandauer opened this issue Dec 10, 2022 · 4 comments

Comments

@ThomasLandauer
Copy link
Contributor

I'm getting:

ERROR: UndefinedFunction - config/packages/mailer.php:12:54 - Function Symfony\Component\DependencyInjection\Loader\Configurator\env does not exist (see https://psalm.dev/021)

ERROR: UndefinedFunction - config/packages/monolog.php:38:16 - Function Symfony\Component\DependencyInjection\Loader\Configurator\param does not exist (see https://psalm.dev/021)

even though I have this in the config files:

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

The file from Symfony is looking like this:

<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

class ContainerConfigurator extends AbstractConfigurator
{
    // ...
}

function param(string $name): ParamConfigurator
{
    // ...
}

function env(string $name): EnvConfigurator
{
    // ...
}

There was a similar issue in PHPStan, and the answer was that this doesn't comply to PSR-4: phpstan/phpstan#5189 (comment)

Is there a solution or a workaround?

@weirdan
Copy link
Member

weirdan commented Dec 10, 2022

Are these functions supposed to be globally available?

@ThomasLandauer
Copy link
Contributor Author

Well, at least in Symfony's config files, see e.g. https://symfony.com/doc/current/configuration.html#configuration-based-on-environment-variables

'url' => env('DATABASE_URL')->resolve(),

@weirdan
Copy link
Member

weirdan commented Dec 11, 2022

Then I believe the easiest workaround is to add that file as a stub in psalm.xml:

<stubs>
   <file name="vendor/symfony/....">
</stubs>

@ThomasLandauer
Copy link
Contributor Author

ThomasLandauer commented Dec 21, 2022

Thanks - works - I added it to README, since (sooner or later) most Symfony users will need it: #297

ThomasLandauer added a commit to ThomasLandauer/psalm-plugin-symfony that referenced this issue Dec 21, 2022
seferov pushed a commit that referenced this issue Dec 22, 2022
seferov pushed a commit that referenced this issue Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants