Skip to content

PHPStan vs Rector

Which should you use? A side-by-side look at what each one does, who it suits, what it costs, how hard it is to set up, and where each falls short.

PHPStan

Open source · MIT

A PHP static analysis tool that finds bugs in code without running it.

Rector

Open source · MIT

Automatically upgrades and refactors PHP code, from PHP 5.3 code up to newer PHP versions.

The short answer

Choose PHPStan if you need…

  • PHP developers who want to catch bugs earlier than tests alone allow
  • Teams maintaining large PHP codebases
  • Developers who want stricter checks on existing PHP code

Choose Rector if you need…

  • PHP teams planning to move an older codebase to a newer PHP version
  • Projects using Symfony, PHPUnit, or Doctrine that want framework-specific upgrade rules
  • Teams that want automated code quality checks in continuous integration
  • Developers who prefer reviewing a diff before applying changes

Side-by-side

PHPStanRector
TypeDev toolDev tool
PriceFree and open sourceFree and open source
LicenceMITMIT
GitHub stars14.1k10.5k
Setup difficultyIntermediateIntermediate
How you get itSee the READMEInstall with a package manager
Main languagePHPPHP
Last code update4 days ago5 days ago

What each one is

PHPStan

PHPStan is a tool that checks PHP code for errors without executing it. It reads your code and reports likely bugs, such as calls that will fail, before you run the code or write tests for it. The README says it aims to make PHP's correctness checkable line by line before running, similar in spirit to compiled languages.

Rector

Rector is a command-line tool that scans PHP code and rewrites it using a set of rules. It can move code toward newer PHP versions and framework versions, and clean up code quality issues. Teams often run it in CI so code quality is maintained automatically.

Best for

PHPStan

  • PHP developers who want to catch bugs earlier than tests alone allow
  • Teams maintaining large PHP codebases
  • Developers who want stricter checks on existing PHP code

Rector

  • PHP teams planning to move an older codebase to a newer PHP version
  • Projects using Symfony, PHPUnit, or Doctrine that want framework-specific upgrade rules
  • Teams that want automated code quality checks in continuous integration
  • Developers who prefer reviewing a diff before applying changes

Strengths

PHPStan

  • Finds whole classes of bugs without needing to run the code
  • Open source under the MIT license with an active project history
  • Official documentation, config reference, and an online playground are available

Rector

  • Covers PHP upgrades from 5.3 to 8.5 according to the README
  • Dry-run mode shows diffs before any file is changed
  • Rules can be used individually or grouped into sets

Not ideal for

PHPStan

  • Non-PHP developers, since it only analyzes PHP code
  • People looking for a runtime testing framework; PHPStan does not run your code, so it complements tests rather than replacing them
  • Those who need a graphical interface without paying, since the web UI is part of the paid PHPStan Pro add-on

Rector

  • Non-PHP projects, since it only works on PHP code
  • Teams that want fully hands-off changes without reviewing diffs, because the README recommends checking results and the tool can produce poorly formatted output
  • Projects without a coding standard tool, because the README says Rector's output usually needs formatting cleanup afterward

Trade-offs

PHPStan

  • The README does not detail setup steps, so you must follow the linked documentation to get started
  • Its most convenient interface (web UI and watch mode) is a paid add-on, PHPStan Pro
  • Static analysis can only judge what it can infer from the code, so results depend on the code's type information

Rector

  • Output can be poorly formatted, so a coding standard tool is needed afterward
  • Parallel mode may have unresolved issues on Windows, per the README
  • Files mixing PHP and HTML may need manual checking after changes

Getting started

PHPStan

Clone the repository

git clone https://github.com/phpstan/phpstan
Step-by-step guide: how to use PHPStan

Rector

Install as a dev dependency

composer require rector/rector --dev

Preview changes on a folder without modifying files

vendor/bin/rector src --dry-run
Step-by-step guide: how to use Rector

Frequently asked questions

What is the difference between PHPStan and Rector?

PHPStan: A PHP static analysis tool that finds bugs in code without running it. Rector: Automatically upgrades and refactors PHP code, from PHP 5.3 code up to newer PHP versions. PHPStan suits php developers who want to catch bugs earlier than tests alone allow, while Rector suits php teams planning to move an older codebase to a newer php version.

Are PHPStan and Rector free?

PHPStan: Free and open source. Rector: Free and open source.

Is PHPStan or Rector more popular?

PHPStan has more GitHub stars (14.1k) than Rector (10.5k). Popularity isn't the same as fit — check which one matches your use case above.

What are other alternatives to PHPStan and Rector?

Other options people compare them with include Infer, PHP CS Fixer.

Keep comparing

Built from our catalogue entries for both products: open-source details come from each project's README (AI-assisted, refreshed weekly) and GitHub data; AI-tool details are editorial. Spotted something wrong? Let us know from either product's page.