How to fix Unexpected item 'parameters › doctrine' in PHPStan doctrine extension

How to fix Unexpected item 'parameters › doctrine' in PHPStan doctrine extension banner

Today while I was configuring PHPStan with the phpstan-doctrine extension I stumbled upon the following error when running PHPStan:

Invalid configuration:
Unexpected item 'parameters › doctrine'.

Here is the full error:

$ vendor/bin/phpstan
Note: Using configuration file /Users/yoan/Development/project/phpstan.dist.neon.
Invalid configuration:
Unexpected item 'parameters › doctrine'.

How to fix this error?

To fix this error you need to include the PHPStan Doctrine extension in your phpstan.neon configuration file.

Open phpstan.neon and add

includes:
    - vendor/phpstan/phpstan-doctrine/extension.neon

parameters:
    level: 5

    # ... other parameters ...

This should do the trick.

What is PHPStan?

PHPStan is a static analysis tool for the PHP programming language. It is designed to analyze your PHP codebase without actually running the code, identifying potential issues, errors, and inconsistencies. This static analysis helps developers catch bugs, improve code quality, and enforce coding standards early in the development process. PHPStan checks for issues such as undefined variables, type mismatches, and other common mistakes, providing feedback to developers before the code is executed. It is commonly used in Continuous Integration (CI) pipelines to automate code analysis and ensure a higher level of code reliability.