Is it possible to set d option for Code Sniffer in PHPStorm
-
21-12-2019 - |
Question
I want to run code inspector in PHPStorm with Code Sniffer package. But Code Sniffer generates lot of useless messages for example "Default timezone is required since PHP 5.4". For manual usage of Code Sniffer I can use d option to set up PHP settings. E.g
phpcs -d date.timezone=Europe/Amsterdam
Is it possible to set up this option for PHPStorm?
Solution
Yes and No (most likely No)
Yes -- you can configure -d
params at PHP Interpreter level.
Settings | PHP
-- click on ...
button to get to list of PHP interpreters.
P.S. This will affect all scripts/tools executed using this particular PHP Interpreter from within IDE.
No -- I strongly believe that PHPCS does not use that PHP Interpreter -- because when you configuring phpcs
, you are providing full path to executable file 1) which will be executed using system default PHP and 2) you cannot pass any custom options when providing it (only path to the file)
Therefore -- better configure default time zone in actual php.ini
OTHER TIPS
It's always better to set timezone system-wide in php.ini
. See PHP datetime configuration documentation. To find out where an active php.ini
is located, you can use function phpinfo()
. CLI PHP uses its own php.ini
. To find out, where it's located you can use for example:
php -i
php -i | grep 'Configuration File'
php --ini
Find "timezone", uncomment and set it according your needs. You can find a list of supported time zones in the PHP documentation.
If you don't have the timezone set, you always get a warning, therefore it's better to set it system-wide. You don't have to care about each script execution then.