Content · Web Development · PHP

Running PHPStan in CI

Run PHPStan after installing locked dependencies in CI so type regressions fail the build before deployment.

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

Run PHPStan after installing locked dependencies in CI so type regressions fail the build before deployment.

What It Does


Run static analysis on every change using a pinned PHP version and locked dependencies. Run the locally installed analyzer against application source.

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


Run static analysis on every change using a pinned PHP version and locked dependencies.

name: Static Analysis
on: [push, pull_request]
jobs:
  phpstan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with: {php-version: '8.4'}
      - run: composer install --no-interaction --prefer-dist
      - run: vendor/bin/phpstan analyse --no-progress

Example 2: Another Case


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 --error-format=github

Practical Example


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

parameters:
  level: 6
  paths:
    - src
  tmpDir: build/phpstan

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


  • Run PHPStan after installing locked dependencies in CI so type regressions fail the build before deployment.
  • 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.