How To Fix the Referenced PHPCompatibility Sniff Error

There are a lot of nice packages that we can use in our PHP-based projects and if you’re using Composer or GrumPHP, PHPCompatibility is one that I recommend including your projects especially if you’re writing code for something that’s going to run across multiple versions of PHP (that is, on hosts that offer different versions).

This is a set of sniffs for PHP CodeSniffer that checks for PHP cross-version compatibility. It will allow you to analyse your code for compatibility with higher and lower versions of PHP.

PHPCompatibility Repository

This is something that be installed within composer and it’s something that I recommend for people writing code for WordPress because of how much variation exists within our hosts.

Occasionally, though, you may see a problem like this:

And if you run $ phpcs -i you may get a message that’s unclear.

Continue reading “How To Fix the Referenced PHPCompatibility Sniff Error”

Modern Software Engineering in WordPress (We Were on a Break)

Over the past few years, I’ve spent a significant amount of time writing about a lot of things on how to achieve certain things in WordPress. And I don’t regret it (after all, it’s my career and it’s even the subtitle and focus of this blog).

But one of the things that I’ve opted to neglect is a focus more on topics that interest me such as object-oriented analysis, programming, design, and implementation. (And, of course, doing so within the context of WordPress.)

And sure, there are some articles where I’ve touched on it but I recently took a week off of pretty much everything except my family and during that time, I took stock of a variety of things.

One of those things included this particular site, its content, and the general focus of my career.

Continue reading “Modern Software Engineering in WordPress (We Were on a Break)”

Participating in Voices of the elePHPant

A few months ago, I had the pleasure of writing the forward to Cal Evans book Using the WordPress REST API. Shortly thereafter, Cal asked if I’d join him on his podcast, Voices of the elePHPant, to talk a bit about software development in the context of WordPress.

And given that that’s what I’ve spent the majority of my career doing, it made sense to participate.

This not only gave me a chance to catch up with Cal “face-to-face” but also to share a bit about what it’s like working in this particular corner of the PHP community and in the WordPress economy.

Continue reading “Participating in Voices of the elePHPant”

Adding Multiple Coding Standards with Composer

It’s one thing to be using PHP CodeSniffer manually but if you’re using a utility such as GrumPHP to check your work before committing it to the repository, then you’re likely going to want to use the version that you’re installing with your project.

This assumes that:

  1. You are installing PHP CodeSniffer local to your project,
  2. You want to install a specific set of coding standards to run against your code.

Remember, this is also done in the context of wanting to run automated scripts during the commit process and in a local environment (versus a global setting) with Composer.

Continue reading “Adding Multiple Coding Standards with Composer”

How To Remove Images with DOMDocument

I’ve written about DOMDocument in a few other posts (1, 2, 3 to share a few) but I continue to find it useful in different ways.

Remember, DOMDocument is a class in PHP that allows us to manipulate the HTML document before rendering it in the browser.

From the manual:

Represents an entire HTML or XML document; serves as the root of the document tree.

Whenever I think of working with the saveHTML function, I think of needing to serialize the new information into a file or other output stream before sending it to the browser.

But we don’t have to do that. It can be done in memory.

Continue reading “How To Remove Images with DOMDocument”