shipmonk/coding-standard
ShipMonk’s PHP_CodeSniffer ruleset for consistent PHP style across ShipMonk packages. Install via Composer, add a phpcs.xml.dist pointing to ShipMonkCodingStandard, then run phpcs to check and phpcbf to auto-fix issues.
composer require --dev shipmonk/coding-standard
phpcs.xml.dist:
Copy the provided XML snippet into your project root. Ensure <file> tags match your project structure (e.g., src/, tests/).vendor/bin/phpcs src/
Verify output for errors/warnings in your codebase.phpcs to validate new developer contributions before PRs.phpcs into your pipeline to block non-compliant code (e.g., GitHub Actions or GitLab CI).phpcs locally via a hook (e.g., with PHP-CS-Fixer or Husky).Daily Development:
phpcs on modified files before committing:
vendor/bin/phpcs src/Feature/NewFeature.php
--standard=ShipMonkCodingStandard to override phpcs.xml.dist temporarily:
vendor/bin/phpcs --standard=ShipMonkCodingStandard src/
Team Enforcement:
# Example GitHub Actions
- name: Run PHP Coding Standard
run: vendor/bin/phpcs --report=full --report-width=120
Automated Fixes:
phpcbf for auto-fixable issues (e.g., indentation, spacing):
vendor/bin/phpcbf src/
composer require --dev friendsofphp/php-cs-fixer
vendor/bin/php-cs-fixer fix src/ --rules=@ShipMonkCodingStandard
vendor/ and generated files (e.g., bootstrap/cache/) in phpcs.xml.dist:
<exclude-pattern>vendor/</exclude-pattern>
<exclude-pattern>bootstrap/cache/*</exclude-pattern>
app/, app/Http/, and routes/ for Laravel projects.ruleset.xml) and reference it:
<rule ref="ShipMonkCodingStandard"/>
<rule ref="ruleset.xml"/>
phpcs for real-time feedback:
Settings > PHP > Quality Tools > PHP Code Sniffer → Path to vendor/bin/phpcs.phpcs.executablePath.Cache Issues:
phpcs behaves unexpectedly, clear the cache:
rm -rf var/phpcs.cache
cache directory in phpcs.xml.dist is writable.Rule Conflicts:
vendor/bin/phpcs --standard=PSR12 src/ # Compare with PSR12
<rule ref="ShipMonkCodingStandard">
<exclude name="Generic.Files.LineEndings"/>
</rule>
Performance:
storage/, public/) to speed up checks:
<exclude-pattern>storage/*</exclude-pattern>
False Positives:
Route::group). Suppress these with:
<exclude name="Generic.Files.DisallowPHPEndTags"/>
--verbose to debug rule application:
vendor/bin/phpcs --verbose src/
Custom Rules:
ruleset.xml:
<rule ref="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint"/>
Severity Adjustments:
phpcs.xml.dist:
<rule ref="ShipMonkCodingStandard">
<severity name="Generic.Files.LineEndings" value="1"/> <!-- 1 = warning -->
</rule>
Sniffs Configuration:
<rule ref="SlevomatCodingStandard.Classes.LineLength">
<properties>
<property name="lineLength" value="140"/>
</properties>
</rule>
phpcs on the entire codebase periodically to catch drift:
vendor/bin/phpcs --report=summary
CONTRIBUTING.md section linking to the ShipMonk Coding Standard for contributors.--report=json for CI to parse violations programmatically:
vendor/bin/phpcs --report=json > phpcs-results.json
How can I help you explore Laravel packages today?