-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Description
Feature request
My team is working with a library that depends on "monolog/monolog": "^1 || ^2". The library is analysed with PHPStan for both versions of dependencies. We use the strict rules. We ran into an issue where method_exists($handler, 'getFormatter') is always true on Monolog 1.x but can be false on Monolog 2.x. This leads to an issue where code like:
if(method_exists($handler, 'getFormatter')) {
// some code
} else {
// more code
}
passes analysis on 2.x, but fails on 1.x (since the expression in the if always evaluates to true). If we ignore the error, then the analysis passes on 1.x, but fails on 2.x (since there's no error to ignore).
Currently I see two ways of solving this:
- (very hacky) Changing the if expression to
method_exists($handler, 'getFormatter') && trueand ignoring the line (there will always be an error (Right side of && is always true.), so this works regardless of whether themethod_existsevaluates to true - (less hacky, but requires duplicating configuration) Using two phpstan.neon files (one for monolog 1.x, another for 2.x) with different
ignoreErrorssections.
My idea of how this could be solved, is to allow to ignore errors unconditionally (i.e. a way to suppress "No error to ignore is reported on line 10.")
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels