Skip to content

Ignore error even if it does not appear in the output #3978

@ramonacat

Description

@ramonacat

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:

  1. (very hacky) Changing the if expression to method_exists($handler, 'getFormatter') && true and ignoring the line (there will always be an error (Right side of && is always true.), so this works regardless of whether the method_exists evaluates to true
  2. (less hacky, but requires duplicating configuration) Using two phpstan.neon files (one for monolog 1.x, another for 2.x) with different ignoreErrors sections.

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.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions