Payton.Codes

Musings on life, games, and code

Payton’s Blog

  • Creating Sniffs for a PHPCS Standard

    Creating Sniffs for a PHPCS Standard

    As a follow-up to my summary of using phpcs to lint your PHP code, this post will explain how to create, modify, and test a phpcs standard. As a quick refresher, phpcs organizes its linting messages (warnings and errors) into “sniffs”, then into “categories”, then into a “standard”. The official tutorial for creating a standard…

  • Linting PHP with phpcs sniffs

    Linting PHP with phpcs sniffs

    Linting is the process of using an automated tool to scan your code for problems before you commit and deploy. It is a practice widely used in the development workflow of many languages, but hasn’t much been used in the PHP of WordPress developers. The most commonly used linter in PHP right now is called…

  • Maybe returning errors in PHP

    Maybe returning errors in PHP

    A common pattern I see in WordPress PHP code (and probably other PHP code) is a function which does some operation on data and returns a value. For example, a function which makes a database query and then returns the resulting row. In order to make more robust code and prevent bugs, I’ve been systematically…

  • Functional Dependency Injection in PHP

    Functional Dependency Injection in PHP

    Having become used to the convenience of passing first-class functions around in JavaScript to make other functions decoupled and easily testable, I was wondering if we could do the same thing in PHP. Of course, PHP technically has first-class functions as well, but the syntax is a little awkward, since the functions must be referenced…

  • Thoughts on Privilege

    Thoughts on Privilege

    Today in my Sangha we explored the concept of Engaged Buddhism, particularly as it applies to race, gender, and class. We explored the most insidious aspect of privilege in our society: that those with privilege do not see it; we are blind to it. White people do not consider race to be a primary factor…

  • Search for the Sage

    Search for the Sage

    My fourth D&D adventure crafted for the Automattic Grand Meetup, Search for the Sage is a one-shot game perfect for new and experienced players alike. It runs in about 3-4 hours. I had a lot of fun creating and running this one! Huge thanks to the many friends who played through this adventure and extra…

  • Declarative vs. Imperative: asking for soup vs. making soup

    Declarative vs. Imperative: asking for soup vs. making soup

    A little while ago I wrote a post about my concepts of declarative vs. imperative programming. I ended that article by saying, “I can’t wait to see what I’ll learn next.” Well, I’ve found another definition which has been very helpful to me lately. Also, I’m a little worried that it might actually be the…

  • Lightweight rendering of React to strings

    Lightweight rendering of React to strings

    For a recent project I needed to be able to render React components (or really, just React-like components) into plain HTML strings. Of course, React provides a mechanism to do this: renderToStaticMarkup in its ReactDOM library. But wow, that library is a really big dependency to import if I don’t want any of the DOM reconciliation…

  • PHP Unit Testing and Pad Thai

    PHP Unit Testing and Pad Thai

    As a follow-up to my last post about PHP unit testing, I recently gave a talk at WordCamp Boston about how to write testable WordPress plugins. You can see the talk slides here: https://payton.codes/testable-wordpress-plugins/ You can also watch the talk here, although the audio quality isn’t great. The premise of my talk was mainly that…