-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Various modules and core classes assume the existance of the Page and PageController classes, when developing a new module that has silverstripe/cms as dependency it is nearly impossible to run phpstan on it due to the way classes are bootstrapped and this implicit dependency on these classes. The analysis breaks with errors like
Error thrown in /app/vendor/silverstripe/cms/code/Model/RedirectorPage.php on line 24 while loading bootstrap file /app/vendor/syntro/silverstripe-phpstan/bootstrap.php: Class "Page" not foundFrom the outside I can't really find a decent way around this, using stubs breaks as this isn't an analysis failure but rather the bootstrap that breaks. Shipping an additional bootstrap file which defines these classes doesn't consistently work and probably shouldn't be considered a real solution because that would mean that every module needs to define those classes somehow and strip them before publishing to prevent issues in websites.
A nice addition to this module would be to handle these cases, so when these classes do not exist (which most likely means that phpstan is ran in a module rather then a fully functional website) define the symbols. As a quick test I've hacked the bootstrap file with a
if (!class_exists('Page')) {
require __DIR__ . '/Page.php';
require __DIR__ . '/PageController.php';
}which causes the analysis to properly run in this module.