mortenson / psalm-plugin-drupal

A project to add Psalm support for Drupal for security testing, focused only on taint analysis.
Other
43 stars 7 forks source link

You have requested a non-existent service "locale.plural.formula". #12

Open ptmkenny opened 1 year ago

ptmkenny commented 1 year ago

This is my first time using psalm, so I might be missing something obvious, but I can't get it to work.

I created a new Drupal 10 site in ddev. My host is on macOS Venture and I have php 8.2 installed locally via homebrew.

I added a very simple module called app_log (info.yml + module.php) and then added psalm.xml and set the module_name in that file. I then ran psalm as described in the documentation and got the following error:

 php ../vendor/mortenson/psalm-plugin-drupal/scripts/dump_script.php && ../vendor/bin/psalm .
Target PHP version: 8.2 (inferred from current PHP version)
Scanning files...
Analyzing files...

Exception: Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException You have requested a non-existent service "locale.plural.formula".
Emitted in /Users/private/d/d10/vendor/symfony/dependency-injection/ContainerBuilder.php:935
Stack trace in the forked worker:
#0 /Users/private/d/d10/vendor/psalm/plugin-symfony/src/Symfony/ContainerMeta.php(155): Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition('locale.plural.f...')
#1 /Users/private/d/d10/vendor/psalm/plugin-symfony/src/Symfony/ContainerMeta.php(64): Psalm\SymfonyPsalmPlugin\Symfony\ContainerMeta->getDefinition('locale.plural.f...')
#2 /Users/private/d/d10/vendor/mortenson/psalm-plugin-drupal/ContainerHandler.php(59): Psalm\SymfonyPsalmPlugin\Symfony\ContainerMeta->get('locale.plural.f...')
#3 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/EventDispatcher.php(318): mortenson\PsalmPluginDrupal\ContainerHandler::afterMethodCallAnalysis(Object(PhpParser\Node\Expr\StaticCall), 'Drupal::service', 'Drupal::service', 'Drupal::service', Object(Psalm\Context), Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(Psalm\Codebase), Array, Object(Psalm\Type\Union))
#4 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/ExistingAtomicStaticCallAnalyzer.php(409): Psalm\Internal\EventDispatcher->dispatchAfterMethodCallAnalysis(Object(Psalm\Plugin\EventHandler\Event\AfterMethodCallAnalysisEvent))
#5 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/AtomicStaticCallAnalyzer.php(876): Psalm\Internal\Analyzer\Statements\Expression\Call\StaticMethod\ExistingAtomicStaticCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(PhpParser\Node\Identifier), Array, Object(Psalm\Context), Object(Psalm\Type\Atomic\TNamedObject), Object(Psalm\Internal\MethodIdentifier), 'Drupal::service', Object(Psalm\Storage\ClassLikeStorage), false)
#6 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/AtomicStaticCallAnalyzer.php(201): Psalm\Internal\Analyzer\Statements\Expression\Call\StaticMethod\AtomicStaticCallAnalyzer::handleNamedCall(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(PhpParser\Node\Identifier), Object(Psalm\Context), Object(Psalm\Type\Atomic\TNamedObject), Array, 'Drupal', false, true)
#7 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php(214): Psalm\Internal\Analyzer\Statements\Expression\Call\StaticMethod\AtomicStaticCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(Psalm\Context), Object(Psalm\Type\Atomic\TNamedObject), false, false, false, true)
#8 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(190): Psalm\Internal\Analyzer\Statements\Expression\Call\StaticCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(Psalm\Context))
#9 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(77): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::handleExpression(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(Psalm\Context), false, NULL, false)
#10 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php(60): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(Psalm\Context))
#11 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(186): Psalm\Internal\Analyzer\Statements\Expression\Call\MethodCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\MethodCall), Object(Psalm\Context))
#12 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(77): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::handleExpression(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\MethodCall), Object(Psalm\Context), false, NULL, false)
#13 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php(156): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\MethodCall), Object(Psalm\Context))
#14 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(546): Psalm\Internal\Analyzer\Statements\ReturnAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Return_), Object(Psalm\Context))
#15 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(207): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Return_), Object(Psalm\Context), NULL)
#16 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php(67): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context))
#17 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php(364): Psalm\Internal\Analyzer\Statements\Block\IfElse\IfAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Internal\Scope\IfScope), Object(Psalm\Internal\Scope\IfConditionalScope), Object(Psalm\Context), Object(Psalm\Context), Object(Psalm\Context), Array)
#18 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(518): Psalm\Internal\Analyzer\Statements\Block\IfElseAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context))
#19 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(207): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context), Object(Psalm\Context))
#20 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php(476): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context), Object(Psalm\Context), true)
#21 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(1795): Psalm\Internal\Analyzer\FunctionLikeAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Internal\Provider\NodeDataProvider), Object(Psalm\Context))
#22 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(1470): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeClassMethod(Object(PhpParser\Node\Stmt\ClassMethod), Object(Psalm\Storage\ClassLikeStorage), Object(Psalm\Internal\Analyzer\TraitAnalyzer), Object(Psalm\Context), Object(Psalm\Context))
#23 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(436): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeTraitUse(Object(Psalm\Aliases), Object(PhpParser\Node\Stmt\TraitUse), Object(Psalm\Internal\Analyzer\ProjectAnalyzer), Object(Psalm\Storage\ClassLikeStorage), Object(Psalm\Context), Object(Psalm\Context), NULL)
#24 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(229): Psalm\Internal\Analyzer\ClassAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Context))
#25 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(362): Psalm\Internal\Analyzer\FileAnalyzer->analyze()
#26 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php(211): Psalm\Internal\Codebase\Analyzer->Psalm\Internal\Codebase\{closure}(29, '/Users/private/...')
#27 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(427): Psalm\Internal\Fork\Pool->__construct(Object(Psalm\Config), Array, Object(Closure), Object(Closure), Object(Closure), Object(Closure))
#28 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(291): Psalm\Internal\Codebase\Analyzer->doAnalysis(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 9)
#29 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(1206): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 9, false, false)
#30 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(375): Psalm\Internal\Analyzer\ProjectAnalyzer->checkPaths(Array)
#31 /Users/private/d/d10/vendor/vimeo/psalm/psalm(7): Psalm\Internal\Cli\Psalm::run(Array)
#32 /Users/private/d/d10/vendor/bin/psalm(120): include('/Users/private/...')
#33 {main} in /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php on line 402 #0 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php(436): Psalm\Internal\Fork\Pool->readResultsFromChildren()
#1 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(503): Psalm\Internal\Fork\Pool->wait()
#2 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(291): Psalm\Internal\Codebase\Analyzer->doAnalysis(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 9)
#3 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(1206): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 9, false, false)
#4 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(375): Psalm\Internal\Analyzer\ProjectAnalyzer->checkPaths(Array)
#5 /Users/private/d/d10/vendor/vimeo/psalm/psalm(7): Psalm\Internal\Cli\Psalm::run(Array)
#6 /Users/private/d/d10/vendor/bin/psalm(120): include('/Users/private/...')
#7 {main}
Exception: Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException You have requested a non-existent service "locale.plural.formula".
Emitted in /Users/private/d/d10/vendor/symfony/dependency-injection/ContainerBuilder.php:935
Stack trace in the forked worker:
#0 /Users/private/d/d10/vendor/psalm/plugin-symfony/src/Symfony/ContainerMeta.php(155): Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition('locale.plural.f...')
#1 /Users/private/d/d10/vendor/psalm/plugin-symfony/src/Symfony/ContainerMeta.php(64): Psalm\SymfonyPsalmPlugin\Symfony\ContainerMeta->getDefinition('locale.plural.f...')
#2 /Users/private/d/d10/vendor/mortenson/psalm-plugin-drupal/ContainerHandler.php(59): Psalm\SymfonyPsalmPlugin\Symfony\ContainerMeta->get('locale.plural.f...')
#3 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/EventDispatcher.php(318): mortenson\PsalmPluginDrupal\ContainerHandler::afterMethodCallAnalysis(Object(PhpParser\Node\Expr\StaticCall), 'Drupal::service', 'Drupal::service', 'Drupal::service', Object(Psalm\Context), Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(Psalm\Codebase), Array, Object(Psalm\Type\Union))
#4 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/ExistingAtomicStaticCallAnalyzer.php(409): Psalm\Internal\EventDispatcher->dispatchAfterMethodCallAnalysis(Object(Psalm\Plugin\EventHandler\Event\AfterMethodCallAnalysisEvent))
#5 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/AtomicStaticCallAnalyzer.php(876): Psalm\Internal\Analyzer\Statements\Expression\Call\StaticMethod\ExistingAtomicStaticCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(PhpParser\Node\Identifier), Array, Object(Psalm\Context), Object(Psalm\Type\Atomic\TNamedObject), Object(Psalm\Internal\MethodIdentifier), 'Drupal::service', Object(Psalm\Storage\ClassLikeStorage), false)
#6 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/AtomicStaticCallAnalyzer.php(201): Psalm\Internal\Analyzer\Statements\Expression\Call\StaticMethod\AtomicStaticCallAnalyzer::handleNamedCall(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(PhpParser\Node\Identifier), Object(Psalm\Context), Object(Psalm\Type\Atomic\TNamedObject), Array, 'Drupal', false, true)
#7 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php(214): Psalm\Internal\Analyzer\Statements\Expression\Call\StaticMethod\AtomicStaticCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(Psalm\Context), Object(Psalm\Type\Atomic\TNamedObject), false, false, false, true)
#8 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(190): Psalm\Internal\Analyzer\Statements\Expression\Call\StaticCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(Psalm\Context))
#9 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(77): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::handleExpression(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(Psalm\Context), false, NULL, false)
#10 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php(60): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(Psalm\Context))
#11 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(186): Psalm\Internal\Analyzer\Statements\Expression\Call\MethodCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\MethodCall), Object(Psalm\Context))
#12 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(77): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::handleExpression(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\MethodCall), Object(Psalm\Context), false, NULL, false)
#13 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php(156): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\MethodCall), Object(Psalm\Context))
#14 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(546): Psalm\Internal\Analyzer\Statements\ReturnAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Return_), Object(Psalm\Context))
#15 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(207): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Return_), Object(Psalm\Context), NULL)
#16 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php(67): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context))
#17 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php(364): Psalm\Internal\Analyzer\Statements\Block\IfElse\IfAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Internal\Scope\IfScope), Object(Psalm\Internal\Scope\IfConditionalScope), Object(Psalm\Context), Object(Psalm\Context), Object(Psalm\Context), Array)
#18 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(518): Psalm\Internal\Analyzer\Statements\Block\IfElseAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context))
#19 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(207): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context), Object(Psalm\Context))
#20 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php(476): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context), Object(Psalm\Context), true)
#21 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(1795): Psalm\Internal\Analyzer\FunctionLikeAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Internal\Provider\NodeDataProvider), Object(Psalm\Context))
#22 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(1470): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeClassMethod(Object(PhpParser\Node\Stmt\ClassMethod), Object(Psalm\Storage\ClassLikeStorage), Object(Psalm\Internal\Analyzer\TraitAnalyzer), Object(Psalm\Context), Object(Psalm\Context))
#23 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(436): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeTraitUse(Object(Psalm\Aliases), Object(PhpParser\Node\Stmt\TraitUse), Object(Psalm\Internal\Analyzer\ProjectAnalyzer), Object(Psalm\Storage\ClassLikeStorage), Object(Psalm\Context), Object(Psalm\Context), NULL)
#24 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(229): Psalm\Internal\Analyzer\ClassAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Context))
#25 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(362): Psalm\Internal\Analyzer\FileAnalyzer->analyze()
#26 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php(211): Psalm\Internal\Codebase\Analyzer->Psalm\Internal\Codebase\{closure}(29, '/Users/private/...')
#27 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(427): Psalm\Internal\Fork\Pool->__construct(Object(Psalm\Config), Array, Object(Closure), Object(Closure), Object(Closure), Object(Closure))
#28 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(291): Psalm\Internal\Codebase\Analyzer->doAnalysis(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 9)
#29 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(1206): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 9, false, false)
#30 /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(375): Psalm\Internal\Analyzer\ProjectAnalyzer->checkPaths(Array)
#31 /Users/private/d/d10/vendor/vimeo/psalm/psalm(7): Psalm\Internal\Cli\Psalm::run(Array)
#32 /Users/private/d/d10/vendor/bin/psalm(120): include('/Users/private/...')
#33 {main} in Psalm\Internal\Fork\Pool->readResultsFromChildren() (line 402 of /Users/private/d/d10/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php).

I made a sample repo here: https://github.com/ptmkenny/drupal10/tree/psalm

Drupal 10.0.3 PHP 8.2 local on macOS (Also tried PHP 8.1 from the ddev container-- same error)

The Drupal site was installed via the CMS quickstart instructions in ddev: https://ddev.readthedocs.io/en/latest/users/quickstart/#drupal

If anyone can point me in the right direction, I'd greatly appreciate it.

mortenson commented 1 year ago

Hi! Have you checked out this issue? https://github.com/mortenson/psalm-plugin-drupal/issues/11

ptmkenny commented 1 year ago

@mortenson Thanks, embarrassingly I missed that issue.

I read through the issue and I updated psalm.xml:

              <module name="app_log" />
              <module name="language" />
              <module name="locale" />

This fixes the error, but now I get a different error:

➜  web git:(psalm) ✗ php ../vendor/mortenson/psalm-plugin-drupal/scripts/dump_script.php && ../vendor/bin/psalm .

Drupal\Core\Database\ConnectionNotDefinedException: The specified database connection is not defined: default in /Users/private/d/d10/web/core/lib/Drupal/Core/Database/Database.php on line 436 #0 /Users/private/d/d10/web/core/lib/Drupal/Core/Database/Database.php(188): Drupal\Core\Database\Database::openConnection('default', 'default')
#1 /Users/private/d/d10/web/core/lib/Drupal/Core/Config/BootstrapConfigStorageFactory.php(40): Drupal\Core\Database\Database::getConnection()
#2 /Users/private/d/d10/web/core/lib/Drupal/Core/Config/BootstrapConfigStorageFactory.php(31): Drupal\Core\Config\BootstrapConfigStorageFactory::getDatabaseStorage()
#3 /Users/private/d/d10/web/core/modules/language/src/LanguageServiceProvider.php(72): Drupal\Core\Config\BootstrapConfigStorageFactory::get()
#4 /Users/private/d/d10/web/core/modules/language/src/LanguageServiceProvider.php(23): Drupal\language\LanguageServiceProvider->isMultilingual()
#5 /Users/private/d/d10/web/core/lib/Drupal/Core/DrupalKernel.php(1277): Drupal\language\LanguageServiceProvider->register(Object(Drupal\Core\DependencyInjection\ContainerBuilder))
#6 /Users/private/d/d10/vendor/mortenson/psalm-plugin-drupal/scripts/PsalmDrupalKernel.php(35): Drupal\Core\DrupalKernel->compileContainer()
#7 /Users/private/d/d10/vendor/mortenson/psalm-plugin-drupal/scripts/PsalmDrupalKernel.php(40): PsalmDrupalKernel->compilePsalmContainer(Array)
#8 /Users/private/d/d10/vendor/mortenson/psalm-plugin-drupal/scripts/dump_script.php(13): PsalmDrupalKernel->dumpContainerXml(Array)
#9 {main}
Drupal\Core\Database\ConnectionNotDefinedException: The specified database connection is not defined: default in Drupal\Core\Database\Database::openConnection() (line 436 of /Users/private/d/d10/web/core/lib/Drupal/Core/Database/Database.php).

In addition, this site is a default standard install profile of Drupal 10, so the language and locale modules are not installed. And my module, app_log, does not even have any php code yet (this is the simplest possible module I could make to test the configuration here). So if there are modules that need to be required even if they aren't installed on the site and aren't dependencies of the custom modules being scanned, I think that should really be documented in the README.

FlorentTorregrosa commented 9 months ago

Hi,

If this may help.

Even without PHP code, as soon as the t function or the related translation service is used. In PHP or maybe with t function in Twig template, the "locale" and "language" modules needs to be listed and it calls the database. So even for static analysis, you need a database connection setup in the settings.php of the environment executing the code analysis.