This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
A PHP_CodeSniffer 3.x coding standard package (aik099/coding-standard). It ships a CodingStandard ruleset made of custom sniffs plus references to built-in PHPCS/Squiz/Generic sniffs, along with the PHPUnit-based test suite that PHPCS itself uses to validate sniffs (fixture .inc files with expected error/warning positions).
Only PHP_CodeSniffer 3.x+ is supported here; the "1.0" branch covers PHPCS 1.x/2.x.
Install dependencies:
composer installRun the full test suite (PHPUnit driving all sniff unit tests):
vendor/bin/phpunitRun a single sniff's test class:
vendor/bin/phpunit CodingStandard/Tests/Classes/ClassNamespaceUnitTest.phpCheck this repo's own source against the standard (dogfooding):
vendor/bin/phpcs --standard=CodingStandard CodingStandard TestSuiteManually inspect/debug a single sniff against its fixture file (sniff.name is the short name after CodingStandard., e.g. Classes.ClassNamespace):
./phpcs-validate.sh Classes.ClassNamespace # full report
./phpcs-validate.sh Classes.ClassNamespace diff # generate a patch, apply it, and produce .fixed reference filesCodingStandard/ruleset.xml— the standard's entry point. It composes this package's own sniffs (CodingStandard.*) with rules borrowed from PHPCS's built-inGenericandSquizstandards, including per-rule severity overrides andexclude-patterns (e.g. member/function naming exceptions for files matchinge_*.php, or excluding*Test.phpfrom one-class-per-file).CodingStandard/Sniffs/<Category>/<Name>Sniff.php— one sniff per file, namespacedCodingStandard\Sniffs\<Category>, implementing PHPCS'sSniffinterface (register()returns the token types to listen for;process()runs when one is encountered and calls$phpcsFile->addError()/addWarning()).CodingStandard/Tests/<Category>/<Name>UnitTest.php— the matching test for each sniff, namespacedCodingStandard\Tests\<Category>, extendingTestSuite\AbstractSniffUnitTest. Each implementsgetErrorList($testFile)/getWarningList($testFile)mapping line numbers to expected violation counts.CodingStandard/Tests/<Category>/<Name>UnitTest*.inc— fixture files phpcs actually scans; multiple numbered fixtures (.1.inc,.2.inc, ...) can exist per sniff for different scenarios. A matching.inc.fixedfile is the expected result after auto-fixing (for sniffs implementingFixer);phpcs-validate.sh ... diffis how these.fixedfiles get (re)generated.TestSuite/bootstrap.phpandTestSuite/AbstractSniffUnitTest.php— vendored/adapted from PHP_CodeSniffer's own test harness; this is what makes PHPUnit understand and run*UnitTest.phpsniff tests found underCodingStandard/Tests(seephpunit.xml.dist).- Naming convention: every category directory name under
Sniffs/andTests/must match (e.g.Sniffs/Commenting/FunctionCommentSniff.phppairs withTests/Commenting/FunctionCommentUnitTest.php+ its.incfixtures), since PHPCS discovers sniffs and matches them to tests by this directory/name convention.
- Add/modify the sniff class under
CodingStandard/Sniffs/<Category>/. - Add/update the fixture (
.inc) and unit test (UnitTest.php) underCodingStandard/Tests/<Category>/with the same base name. - Reference new sniffs from
CodingStandard/ruleset.xmlif they should be enabled by default (custom sniffs underCodingStandard.*are auto-included; only exceptions/severities/excludes need explicit entries). - Run
vendor/bin/phpunit(or the single test class) to verify expected error/warning lines match.