If you're using tools like PHPStan on your projects you'll already be reaping the benefits. However are you using them to their full potential?

Do you have conventions on your project that you have to remember, either when writing or during code review? (E.g. a certain object should only be built by a factory. Or a method should only be used for testing.) Do you wish you could automate the checking of these conventions so they'd never be forgotten?

Or do you wish PHP had features that other languages had, e.g. Java's package visibility modifier?

The great news is PHPStan allows you to write your own custom rules to enforce all kinds of conventions or new language features.

This tutorial will guide you through the basics of writing your own rules for PHPStan. We'll create a couple of simpler rules together and by the end of the session you'll be in a position to start writing your own rules.

NOTE: This tutorial assumes you already use PHPStan on a regular basis.

Comments

Comments are closed.

Joe Theuerkauf at 09:34 on 5 Nov 2022

Well prepared tutorial code, clearly explained. Quick pace because building rules is still a fairly involved multi-step process, but it becomes clear how powerful the tool can be.