Content · Web Development · PHP

Configuring PHPStan Strictness Levels

PHPStan levels control how aggressively unknown types, mixed values and other risky operations are reported during static analysis.

1 views Published Oct 17, 2026 Updated Oct 17, 2026 admin

PHPStan levels control how aggressively unknown types, mixed values and other risky operations are reported during static analysis.

What It Does


Start with explicit analysis paths and a strictness level appropriate for the codebase. A list<int> annotation supplements PHP’s built-in array type.

Requirements and Compatibility


Use a supported PHP runtime and install any third-party tool or extension explicitly shown in the examples. Commands should be run from the project root unless stated otherwise.

Syntax, Inputs and Results


The examples separate configuration, the smallest working operation and a realistic follow-up task. Adapt file paths and dependency versions to your own project.

Example 1: Basic Use


Start with explicit analysis paths and a strictness level appropriate for the codebase.

parameters:
  level: max
  paths:
    - src
  tmpDir: build/phpstan
  reportUnmatchedIgnoredErrors: true

Example 2: Another Case


A list<int> annotation supplements PHP’s built-in array type.

<?php
/** @param list<int> $prices */
function totalCents(array $prices): int { return array_sum($prices); }
echo totalCents([120, 240]);

Practical Example


Run the locally installed analyzer against application source.

composer require --dev phpstan/phpstan
vendor/bin/phpstan analyse src --level=max --no-progress
vendor/bin/phpstan analyse --level=max

For production, apply the compatibility and edge-case limits described below.

Important Behavior and Edge Cases


A green analysis does not replace runtime tests or prove business logic.

Comparison with Related Functions and Tools


SubjectKey difference
Static analysis vs runtime testsPHPStan checks source types without executing business behavior; tests confirm actual outcomes.

Common Beginner Mistakes


MistakeCorrect approach
Ignoring unknown or mixed typesAdd valid PHPDoc element types or proper native declarations, then re-run the analyzer.
Skipping the prerequisite of this specific workflowInstall or configure the named tool and confirm the example can actually run.
Ignoring edge conditionsA green analysis does not replace runtime tests or prove business logic.

Key Takeaways


  • PHPStan levels control how aggressively unknown types, mixed values and other risky operations are reported during static analysis.
  • A green analysis does not replace runtime tests or prove business logic.
  • Keep application configuration, source code and validation tests under version control.

Use these examples as a starting point, then validate the result with the actual PHP build, dependencies and inputs used by your application.

Share this resourceSend this page to someone who may find it useful.