In the last article, we identified that the task of generating posts, albeit arbitrary, is just one possible implementation of getting content for a search query. As such, we split the tasks of “getting content” and “generating posts” into separate methods. This design sets us up for a discussion about designing swappable search request implementations. Before we get started, I want to remind you that Josh designed this plugin for educational purposes in order to teach you Advanced OOP and testing. As you and I work through the code review together, the tasks of “getting content” reveals itself as a […]
Code Review Part 3 – Building & Refactoring the Posts Generator
In the last article, I walked you through a code review and refactoring process for the FilterWPQuery class in Josh Pollock’s plugin. We made his class more readable and performant. But we did not cover the posts generator code in the getPosts() method; rather, I left that review for this article. Why? There are two reasons. First, I wanted to give us time to thoroughly review this section of code. There are several areas that we can improve. This code provides a learning opportunity to improve your own code as we dive into code style, PHP namespace importing, string processing, and more. […]
Code Review Part 2: Improving Readability and Performance of the FilterWPQuery Class
In the last article, I walked you through the problem of letting “no go” conditions flow through your code. I showed you how to refactor the code to solve the problem and make the code more readable. In this article, you and I will continue doing a code review and refactoring of the FilterWPQuery in Josh Pollock’s plugin. In Part 3 of Advanced OOP for WordPress, Josh walks you through how he refactored the FilterWPQuery class to make it more testable. Let’s use his latest version of the class for our code review process. <?php namespace CalderaLearn\RestSearch; /** * Class FilterWPQuery * […]
Code Review Part 1: Fixing Design Flaw with the “Return Early” Strategy
While reading Josh Pollock’s first article in his Advanced OOP for WordPress series, I noticed opportunities to improve his code’s quality and performance. So I reached out to him. As a fellow educator, he suggested that I do a code review and then publish my insights in a series of articles here on Torque as a companion to his series. In this Code Quality Review series, I will present one or more code quality opportunities and provide details and insights to help you improve your code. Let’s start with the posts_pre_query method in his FilterWPQuery class: <?php class FilterWPQuery { […]
2 Comments