Closed FlorentTorregrosa closed 1 year ago
@FlorentTorregrosa Is the locale
module enabled in your psalm config? Ex:
<pluginClass class="mortenson\PsalmPluginDrupal\Plugin">
<containerXml>DrupalContainerDump.xml</containerXml>
<extensions>
<module name="field" />
<module name="language" />
<module name="file" />
<module name="locale" />
</extensions>
</pluginClass>
Thanks @mortenson for the quick feedback.
It was not present. But I still got the error with the module listed.
I tried to debug in the DrupalKernel to follow the flow of the error stacktrace.
In app/core/lib/Drupal/Core/DrupalKernel.php, I put some debug:
$yaml_loader = new YamlFileLoader($container);
foreach ($this->serviceYamls['app'] as $filename) {
if ($filename == 'core/modules/locale/locale.services.yml') {
$container->has('locale.plural.formula') ? var_dump('yes') : var_dump('no');
}
$yaml_loader->load($filename);
if ($filename == 'core/modules/locale/locale.services.yml') {
$container->has('locale.plural.formula') ? var_dump('yes') : var_dump('no');
}
}
It gave:
Target PHP version: 8.1 (inferred from current PHP version)
Scanning files...
string(2) "no"
string(3) "yes"
Analyzing files...
Exception: Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException You have requested a non-existent service "locale.plural.formula".
So I guess the services definitions are loaded correctly. But lost during analysis.
Also I realized that all the modules enabled in my current instance are loaded, not only the one listed in the psalm config. If I put:
// Register application services.
$yaml_loader = new YamlFileLoader($container);
foreach ($this->serviceYamls['app'] as $filename) {
var_dump($filename);
$yaml_loader->load($filename);
}
I see all the services.yml files of my enabled modules.
When looking at the Drupal psalm plugin I saw:
// Copies Psalm\SymfonyPsalmPlugin\Handler\ContainerHandler to support Drupal::service.
in vendor/mortenson/psalm-plugin-drupal/ContainerHandler.php
So I wonder if this class should not be updated because there are been changes between the 2.x and 4.x version of the Symfony plugin.
About "Also I realized that all the modules enabled in my current instance are loaded, not only the one listed in the psalm config.". This is because in vendor/mortenson/psalm-plugin-drupal/scripts/PsalmDrupalKernel.php::getPsalmModuleList:
foreach ($xml->xpath('//pluginClass[@class="mortenson\PsalmPluginDrupal\Plugin"]/extensions/module') as $node) {
}
This xpath expression is not working (at least for me). If I dump the $xml I have my xml file loaded but not getting in the foreach.
Edit:
Found the problem. at the beginning of my psalm.xml I have:
<psalm
...
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
The xpath does not like those 3 lines.
WTF, and now it is working...
Edit: I mean, without those 3 lines, I do not have the problem of service not found... Checking on somewhere else than my computer.
Checked on some else project. I was those 3 lines...
Hi,
On either Drupal 9 and Drupal 10 with the latest version of psalm drupal plugin, when trying to scan files. I get this error.
I have rolled back on https://github.com/mortenson/psalm-plugin-drupal/commit/48e3cbc34dcc90ec7b196b1130c68cdaabb63118 (the version before recent changes). And I also obtain the error.
So I guess this is due to an update in Symfony?