I’m very much a fan of GrumPHP which I’ve written extensively about in previously posts.

And as my last past alluded, I’ve been adapting a piece of software so it maximizes its availability across all platforms using PHP regardless of now new or how old the platform is (at least between PHP 7.2 and PHP 8).

Here’s the thing, though: If you’re working with an older version of PHP then you’re going to need an older version of GrumPHP and if you’re going to use an older version, you may need an older version of Composer.

Except maybe not!

GrumPHP, Composer 2 and PHP 7.2

Once of the nicest things about Composer 2 is how much faster its become. So it raises a question: Is there a version of the packages that we’re using that simultaneously work with older versions of PHP (like PHP 7.2) and still work with Composer 2?

With some packages, no. Unfortunately, you have to fall back to Composer 1. But if at all possible, use Composer 2. And luckily, if you’re using GrumPHP and Composer 2, there is a version of the library that works with Composer 2.

What really got my started on all of this was the following message:

  Problem 1
    - Root composer.json requires phpro/grumphp v0.8.0 -> satisfiable by phpro/grumphp[v0.8.0].
    - phpro/grumphp v0.8.0 requires composer-plugin-api ~1.0 -> found composer-plugin-api[2.3.0] but it does not match the constraint.

Note that I was running PHP 7.2 and Composer 2 while trying to find a version of GrumPHP that supports Composer 2. It’s a tedious task but here’s what you need:

  1. Composer 2
  2. PHP 7.2
  3. GrumPHP v0.18.1

This allow GrumPHP to work with libraries that will sniff out issues with your codebase all the while working with Composer 2.

I don’t know if other versions will do this, but I know that this version works. This means my composer.json looks like this (well, part of it at least):

"require-dev": {
    "phpro/grumphp": "v0.18.1",
    "squizlabs/php_codesniffer": "^3.5",
    "phpcompatibility/php-compatibility": "^9.3.5",
    "sensiolabs/security-checker": "^4.0"
},

Then in the terminal if you run:

~ composer update

You should see the usual feedback you expect (which should either be All Good or the alternative 🙂).

So if you’re looking to use GrumPHP, Composer 2, and PHP 7.2, this is how you make it happen successfully.