ILIAS uses PHPStan as an optional tool for developers
to find errors in the ILIAS code base without actually running it.
To provide a common configuration a shared config file is located in
./scripts/PHPStan/phpstan.neon.
PHPStan provides the possibility to analyse the code based on specfic
rule levels.
The level used in ILIAS is level 6, which includes the reporting of missing typehints.
To prevent False Positives beingt reported related to global constants, developers can extend the constant collection
defined in the constants.php
To run PHPStan you just need to execute the bash script:
./scripts/PHPStan/run_check.shTo run PHPStan in the context of a specific component, pass the respective folder name as argument:
./scripts/PHPStan/run_check.sh components/ILIAS/MailYou can overwrite the rule level by passing a --level argument:
./scripts/PHPStan/run_check.sh components/ILIAS/Mail --level 3A custom configuration file could be provided by adding a file named phpstan.local.neon to the ILIAS root directory.
The filename is ignored by the .gitignore file and ILIAS \RootFolderTest, which ensures no new files are added
to the root level of ILIAS.
Example:
includes:
- scripts/PHPStan/phpstan.neon
parameters:
level: 9In this example the shared PHPStan configuration is extended by the local configuration, where we defined stricter
rule level.
A baseline file can be generated by using the --generate-baseline option.
/scripts/PHPStan/run_check.sh -c phpstan.local.neon components/ILIAS/Mail --generate-baselineThe generated baseline file phpstan-baseline.neon will be stored in the ILIAS root folder and must be included in the
local phpstan.local.neon configuration.
includes:
- scripts/PHPStan/phpstan.neon
- phpstan-baseline.neon
parameters:
level: 9If you analyse different components/folders with PHPStan, you will need to generate a new baseline file.
See: https://www.jetbrains.com/help/phpstorm/using-phpstan.html