There can be a situation where you have to exclude a class or even an entire file from being checked by PHPStan against defined rules in your project. This guide explains how to exclude a file by the given path name and keep the pipeline green.
Open your phpstan.neon
file, typically it should be right in the root of your project.
Assuming we want to exclude a dummy controller located at:
src/app/Http/Controllers/Backend/TestController.php
All we have to do is to define excludePaths
under parameters
with the given path:
includes:
- vendor/larastan/larastan/extension.neon
parameters:
paths:
- app/
excludePaths:
- app/Http/Controllers/Backend/TestController.php
level: 5
This is everything to exclude a specific file from PHPStan checks.
Running checks will now bypass excluded files.