PHPStan: Find Bugs In Your Code Without Writing Tests!

When do you find out about errors?

Enter PHPStan

It’s called PHPStan, it’s open-source and free to use.

What it currently checks for?

  • Existence of classes used in instanceof, catch, typehints and other language constructs. PHP does not check this and just stays instead, rendering the surrounded code unused.
  • Existence and accessibility of called methods and functions. It also checks the number of passed arguments.
  • Whether a method returns the same type it declares to return.
  • Existence and visibility of accessed properties. It will also point out if a different type from the declared one is assigned to the property.
  • Correct number of parameters passed to sprintf/printf calls based on format strings.
  • Existence of variables while respecting scopes of branches and loops.
  • Useless casting like (string) ‘foo’ and strict comparisons (=== and !==) with different types as operands which always result in false.

PHPStan is fast…

…and extensible

Choose your level of strictness

Write less unit tests! (but focus on the meaningful ones)

On the shoulders of giants

If you’re a PHP developer, give PHPStan a shot. If you’re interested in various insights about software development, follow me on Twitter. If you’re interested in my consulting services on code quality, continuous delivery, hiring developers, open-source and plethora of other topics, please get in touch.

--

--

--

Author of PHPStan, static analysis tool for finding bugs in code without running it.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ondřej Mirtes

Ondřej Mirtes

Author of PHPStan, static analysis tool for finding bugs in code without running it.

More from Medium

Tests are important and here’s WHY!

Solid Principles

Create Unit tests for WordPress Plugin

Converting Your Test Suite to PEST