Skip to main content

PHPStan with Docker

php-ci ships with the PHP extensions and Composer tooling you need to run PHPStan in CI. Install PHPStan as a project dev dependency and invoke it from ./vendor/bin/phpstan.

Local run

docker run --rm -v "$(pwd):/app" -w /app himanshuramavat/php-ci:8.3 bash -c '
composer install --no-interaction --prefer-dist &&
./vendor/bin/phpstan analyse src --memory-limit=1G
'

Raise --memory-limit for large codebases. PHPStan reads phpstan.neon or phpstan.neon.dist from your project root automatically.

In CI

Use the same command in any provider — swap the job syntax for yours:

Minimal GitHub Actions job:

jobs:
analyse:
runs-on: ubuntu-latest
container:
image: himanshuramavat/php-ci:8.3
steps:
- uses: actions/checkout@v4
- run: composer install --no-interaction --prefer-dist
- run: ./vendor/bin/phpstan analyse src --memory-limit=1G

Tips

  • Pin PHPStan in composer.json so CI and local runs use the same version.
  • Combine with PHPUnit in a single composer ci script — see Generic PHP.
  • If analysis fails with missing extensions, check PHP Extensions.