Lesson 9.2. Code Review and Standards

Goal

Review WooCommerce code with a checklist and automate the standards.

Key concepts

  • WordPress Coding Standards (WPCS) through PHPCS; WooCommerce rules — woocommerce/woocommerce-sniffs
  • PHPStan for types and logic errors; WordPress and WooCommerce need stubs (szepeviktor/phpstan-wordpress, php-stubs/woocommerce-stubs)
  • Automation in CI on every PR, a human for architecture and business logic
  • The WooCommerce checklist: CRUD instead of post meta, HPOS, both checkouts, idempotency, security, i18n, performance
  • Review tone: questions and suggestions with an explanation, not orders

Diagram

flowchart LR
  PR["Pull Request"] --> CI["CI: PHPCS, PHPStan,<br/>tests"]
  CI -- red --> FIX["The author fixes it"]
  CI -- green --> HUM["Human review:<br/>WooCommerce checklist"]
  HUM --> MERGE["Merge"]

Code

phpcs.xml.dist:

XML
<?xml version="1.0"?>
<ruleset name="My WC Extension">
	<file>./src</file>
	<file>./my-wc-extension.php</file>
	<exclude-pattern>/vendor/*</exclude-pattern>
	<rule ref="WordPress-Extra"/>
	<rule ref="WooCommerce-Core"/>
	<config name="minimum_supported_wp_version" value="6.5"/>
	<rule ref="WordPress.WP.I18n">
		<properties>
			<property name="text_domain" type="array" value="my-wc-extension"/>
		</properties>
	</rule>
</ruleset>

WooCommerce review checklist

QuestionWhat we look for
DataCRUD, not get_post_meta / update_post_meta for products and orders
HPOSNo shop_order in WP_Query and no SQL against wp_posts
CheckoutWorks in classic and block; fields through the fields API
BackgroundExternal APIs in a queue, idempotent jobs
SecurityNonce, permissions, sanitizing, escaping, prepare
PerformanceNo queries in loops, there is a cache and pagination
i18nEvery string in __() with the right text domain
CompatibilityFeature declarations, WC tested up to

Common mistakes

SymptomCauseFix
The review turns into arguments about spacesStyle isn't automatedPHPCS in CI and pre-commit
An HPOS bug passed the reviewNo WooCommerce checklistThe checklist in the PR template
A junior is afraid of reviewsComments without explanationsExplain "why" and give links

Weak and strong answer

Question: What do you look at in a code review of a WooCommerce plugin?

Weak answer. Code style and whether there are bugs.

Strong answer. CI catches style and basic errors (PHPCS, PHPStan). I look at what automation doesn't see: whether data goes through CRUD and is HPOS compatible, whether the solution works in block checkout, whether we make external requests inside the customer's request, handler security, query performance. I write comments with explanations so the review teaches, not only blocks.

Why the second is stronger: A split between automation and a human, a concrete checklist and a mentoring approach (a requirement of the job posting).

Practice

In the terminal run PHPCS and PHPStan, see why PHPStan fails without stubs, install them and run it again.

On your own plugin: set up PHPCS with WordPress-Extra and WooCommerce-Core and fix all the errors. Review the code from lesson 8.3 with the checklist and write 3 comments as if the review were for a junior.

composer / wp — Module 9. Quality and Production

Interview Questions

PHPCS checks style and patterns (WPCS: escaping, nonce, prepare). PHPStan is static analysis of types and logic: non-existent methods, wrong types, dead code.

The big picture first, then the details. Separate the must-haves from the nice-to-haves. Explain the reason and give links. Praise good decisions. Big changes — talk them through, not 40 comments.

Style (PHPCS), static analysis (PHPStan), tests, the JS build. The human keeps architecture, business logic and security in context.

Save your progress

Sign in or create a free account to mark lessons as completed and continue the whole course. You will come back to this lesson.