phpcsstandards/phpcsutils
Utilities and helper classes for building and maintaining PHP_CodeSniffer (PHPCS) standards and sniffs. Provides common abstractions and compatibility helpers to simplify writing custom rulesets and speed up development of consistent coding standards.
Start by installing the package via Composer to complement PHP_CodeSniffer (PHPCS) in your custom sniffs or scripts:
composer require phpcsstandards/phpcsutils --dev
The primary entry point is the PHP_CodeSniffer\Util\Tokens and PHP_CodeSniffer\Files\File utilities—explore src/ in the repository for classes like Common, Tokens, and Variables. The first use case is typically writing custom sniffs: use Tokens::getCondition() to analyze token context, or Common::isAssignment() to detect variable assignments in code. Check the examples/ directory if available for quick sniff templates.
Tokens::getPropertyDecorators() to extract PHP 8 attributes or Common::isReference() for by-reference checks—saving time over raw token traversal.Tokens::getNext() and Tokens::findPrevious() with chained filters (e.g., Tokens::emptyTokens) to skip whitespace/comments robustly.Variables::get declaredVariable() and Variables::getCondition() to track variable scope and usage across blocks.phpcs.xml or phpcs.xml.dist; they integrate directly with PHPCS’ command-line interface without extra setup.composer require phpcsstandards/phpcsutils:^1.0 per PHPCS version.T_WHITESPACE checks; use Tokens::emptyTokens (includes comments, newlines, etc.) to ensure portable sniff logic.Tokens::getCondition() may require passing the current file pointer explicitly—don’t rely on implicit state.-vv) to inspect actual token sequences when utilities like Variables::getMemberVar SCOPE() behave unexpectedly.Sniff from PHPCS and utility classes directly (e.g., use PHP_CodeSniffer\Util\Tokens;) rather than wrapping them—minimize abstraction unless adding project-specific helpers.How can I help you explore Laravel packages today?