In this case, you want to analyse the whole src directory, but want to exclude src/thirdparty from analysing. If your project’s directory structure mixes your own code (the one you want to analyse and fix bugs in) and third party code (which you’re using for discovering symbols, but don’t want to analyse), the file structure might look like this: ├── phpstan.neon This is a shortcut for: parameters : excludePaths : analyseAndScan : - tests/ */data/* parameters : excludePaths : - tests/ */data/* Each entry is used as a pattern for the fnmatch() function. to test behaviour of your application on files with invalid PHP code), you can exclude them using the excludePaths key. If your codebase contains some files that are broken on purpose (e. parameters : reportUnmatchedIgnoredErrors : false ignoreErrors : - '#This message will not be reported as unmatched#' - '#This message will not be reported as unmatched either#' - message : '#But this one will be reported#' reportUnmatched : true parameters : reportUnmatchedIgnoredErrors : true ignoreErrors : - '#This message will be reported as unmatched#' - '#This message will be reported as unmatched too#' - message : '#But this one will not be reported#' reportUnmatched : false Excluding whole files # This overwrites global reportUnmatchedIgnoredErrors setting. You can turn on/off reporting unused ignores explicitly for each entry in ignoredErrors. You can turn off this behaviour by setting reportUnmatchedIgnoredErrors to false in the configuration: parameters : reportUnmatchedIgnoredErrors : false If some of the ignored errors (both from configuration and PHPDocs) do not occur in the result anymore, PHPStan will let you know and you will have to remove the pattern from the configuration. If you want to ignore all the current errors and only focus on new and changed code from now on, go and learn about the baseline feature. It deals with the complexity of writing a matching regular expression from a plain string and encoding that regular expression into the neon format.Īn error occurred. Using the fields below, you can generate an entry that you can put in the parameters.ignoreErrors section of your configuration file. So if your phpstan.neon is in the root directory of the project, and you want to ignore an error in src/Foo/Bar.php, your path key can simply be src/Foo/Bar.php. Relative paths in the path and paths keys are resolved based on the directory of the config file is in. message : '#Call to an undefined method +::doFoo\(\)#' path : other/dir/DifferentFile.phpĬount : 2 # optional - '#Other error to ignore everywhere#' messages : - '#Call to an undefined method +::doFooFoo\(\)#' - '#Call to an undefined method +::doFooBar\(\)#' paths : - some/foo/dir/* messages : - '#Call to an undefined method +::doFooFoo\(\)#' - '#Call to an undefined method +::doFooBar\(\)#' path : other/dir/AnotherFile.php message : '#Call to an undefined method +::doBar\(\)#' paths : - some/dir/* parameters : ignoreErrors : - message : '#Access to an undefined property +::\$foo#' path : some/dir/SomeFile.php You can specify how many times the error is expected by using count (optional, applies only to message not messages and path, not paths). Wildcard patterns compatible with the PHP fnmatch() are also supported. To ignore errors by a regular expression only in a specific file, add an entry with message or messages and path or paths keys. To ignore an error by a regular expression in the whole project, add a string entry: parameters : ignoreErrors : - '#Call to an undefined method +::doFoo\(\)#' - '#Call to an undefined method +::doBar\(\)#' Custom error formatters also have the error identifiers at their disposal in order to output them.Įrrors can be ignored by adding a regular expression to the configuration file under the ignoreErrors key.It will output the identifier next to the error message. By reproducing your error in the playground.It will output your errors along with their identifiers in a beautiful web UI. The default table error formatter will output the error identifier below the error message. You can find out the error identifier for the error you’re trying to ignore: It requires an error identifier to only ignore a specific error instead of all errorsįunction ( ).If there’s no code on the line with the comment, it ignores the next line. It figures out automatically if you want to ignore an error on the current line or the next line.If you want to ignore only a specific error, you can take advantage of error identifiers and use the new tag that comes with two features:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |