-
Notifications
You must be signed in to change notification settings - Fork 696
Closed
Labels
Description
I'm using a php file with constants as configuration, like this (config.php):
<?php
/**
* Enables debug mode, bla bla bla
*
* @var bool
*/
const DEBUG = false;This file is required() from a bootstrap file before classes that make use of these constants are autoloaded.
In my psalm.xml I list <file name="config.php"> in <projectFiles>, but then psalm complains about UndefinedConstant violations in other files:
ERROR: UndefinedConstant - src/Templating/Template.php:29:29 - Const DEBUG is not defined (see https://psalm.dev/020)
$options["debug"] = DEBUG;
I found #2644 where <stubs> are suggested. Adding config.php as a stub fixes these warnings, but now psalm also uses the predefined values of these constants for analysis and as a result finds violations like this:
ERROR: TypeDoesNotContainType - src/Templating/Template.php:30:29 - if (false) is impossible (see https://psalm.dev/056)
$options["cache"] = DEBUG ? false : self::CACHE_DIR;
How to handle this case? I cannot define the constants without values because that is a syntax error. Thanks.
Reactions are currently unavailable