graze/standards
Graze Coding Standards: a cross-language style guide for the Graze tech team. Covers general formatting rules, Git conventions, and standards for PHP, HTML, JavaScript, Python, SQL, CSS/Less, Markdown, and Go, plus open source and environment guidance.
Installation:
composer require --dev graze/standards
Add to your project's phpcs.xml or phpcs.xml.dist:
<config name="installed_paths" value="./vendor/graze/standards"/>
First Run:
vendor/bin/phpcs --standard=Graze src/
Verify compliance with Graze’s PHP standards (e.g., abstract class naming, negation spacing).
Quick Check:
Use the -s flag for snippet-style output:
vendor/bin/phpcs -s --standard=Graze app/Http/Controllers/
phpcs on a new PR to catch formatting/naming violations early.Foo?" → "Graze requires AbstractFoo").Pre-Commit Hook:
Integrate with phpcs via a hook (e.g., using php-cs-fixer or a custom script):
# Example: Fail build if violations exist
vendor/bin/phpcs --standard=Graze --warning-severity=0 src/ || exit 1
CI Pipeline:
Add to Laravel’s GitHub Actions (.github/workflows/lint.yml):
- name: PHP Coding Standards
run: vendor/bin/phpcs --standard=Graze --warning-severity=0 src/
IDE Integration:
phpcs as an external tool (Settings → Tools → External Tools).phpcs integration.Abstract Classes:
Enforce Abstract prefix (e.g., AbstractUserRepository) via the Graze.Naming.AbstractClassNaming sniff.
// ✅ Valid
abstract class AbstractUserRepository { ... }
// ❌ Invalid (will trigger sniff)
abstract class UserRepository { ... }
Negation Operators:
Avoid spaces after ! (e.g., $isValid = !$input->valid() instead of $isValid = ! $input->valid()).
DocBlocks: Ensure child functions in anonymous functions have docblocks:
$callback = function() {
/** @return string */
function inner() { return 'ok'; }
};
Custom Rulesets:
Override Graze’s rules in phpcs.xml:
<rule ref="Graze">
<exclude name="Graze.ControlStructures.NegationNoSpaces"/>
</rule>
Add New Sniffs:
Extend Graze\Sniffs\BaseSniff and register in Graze\Sniffs\Register.php.
Sniff Naming:
graze.controlStructures.NegationNoSpaces).phpcs and use the fully namespaced format (Graze.ControlStructures.NegationNoSpaces).Abstract Class Crashes:
class Foo {}) could crash the AbstractClassNaming sniff (<2.0.2).v2.0.2+ or avoid empty abstract classes.DocBlock Parsing:
Line Endings:
CRLF/LF can cause phpcs to flag "trailing whitespace" falsely.dos2unix src/
Verbose Output:
Use --verbose to debug sniff failures:
vendor/bin/phpcs --standard=Graze --verbose app/Models/
Isolate Sniffs:
Test individual sniffs with --sniffs:
vendor/bin/phpcs --standard=Graze --sniffs=Graze.Naming src/
Partial Compliance:
Use --ignore to bypass specific rules temporarily:
vendor/bin/phpcs --standard=Graze --ignore=Graze.ControlStructures.NegationNoSpaces app/
Autofix:
Combine with php-cs-fixer for automatic fixes:
vendor/bin/php-cs-fixer fix --rules=@Graze --dry-run
Documentation:
make docs-test # Starts MkDocs on port 8000
Laravel-Specific:
Abstract (e.g., AbstractMailServiceProvider).snake_case for table/column names (covered in SQL docs).Performance:
Cache phpcs results for large codebases:
vendor/bin/phpcs --standard=Graze --cache-file=.phpcs.cache src/
How can I help you explore Laravel packages today?