instaclick/object-calisthenics-sniffs
Installation Add the package via Composer in your Laravel project:
composer require --dev instaclick/object-calisthenics-sniffs
Ensure phpcs (PHP_CodeSniffer) is installed globally or via Composer:
composer global require squizlabs/php_codesniffer
First Use Case
Run a basic sniff check on your Laravel app’s app/ directory:
phpcs --standard=./vendor/instaclick/object-calisthenics-sniffs app/
This enforces Object Calisthenics principles (e.g., no getters/setters, no literals, etc.) by default.
Where to Look First
./vendor/instaclick/object-calisthenics-sniffs/ruleset.xml for customizable rules.phpcs.xml (e.g., exclude app/Providers/ if needed).Integrate into CI/CD
Add a phpcs step to your GitHub Actions/GitLab CI:
- name: Run Object Calisthenics Sniffs
run: phpcs --standard=./vendor/instaclick/object-calisthenics-sniffs --report=json app/ > phpcs-results.json
Fail the build if violations exceed thresholds (e.g., phpcs --warning-severity=5).
Laravel-Specific Workflows
app/Domain/Entities/).return 42;) with injected constants or config files.Custom Rulesets
Extend the default ruleset in phpcs.xml:
<config name="instaclick_object_calisthenics" value="./vendor/instaclick/object-calisthenics-sniffs/ruleset.xml"/>
<arg name="extensions" value="php" />
<arg name="tab-width" value="4" />
<arg name="encoding" value="utf-8" />
Pair with Other Tools
phpstan/extension-installer to catch type-related violations.squizlabs/php_codesniffer for broader standards.phpcs --ignore=app/OldCode app/
app/Http/Controllers/) before full enforcement.phpcs on save using the phpcs.xml ruleset.Overly Strict Defaults
phpcs.xml:
<rule ref="ObjectCalisthenics.Sniffs.NamingConventions.NoGetterSetterMethodsSniff" severity="0"/>
False Positives in Legacy Code
--ignore or annotate code with @phpcs:disable:
// @phpcs:disable ObjectCalisthenics.Sniffs.NamingConventions.NoGetterSetterMethodsSniff
public function getName() { ... }
Performance Overhead
phpcs on large codebases (e.g., 10K+ files) can be slow.phpcs --parallel=4 app/
Laravel-Specific Exceptions
Route::get()) or magic methods (e.g., __get()) may violate rules.app/Providers/ or use @phpcs:ignore for Facades.--verbose to identify which files/rules are failing:
phpcs --standard=./vendor/instaclick/object-calisthenics-sniffs --verbose app/
NoGetterSetterMethodsSniff) for exceptions.Custom Sniffs
Extend the package by creating your own sniffs in app/CodeSniffer/ and reference them in phpcs.xml:
<rule ref="app/CodeSniffer/Custom/NoMagicMethodsSniff"/>
Dynamic Rules
Use PHP_CodeSniffer’s processFile to skip files conditionally (e.g., based on namespace):
// In a custom sniff
if (strpos($file, 'app/Tests/') !== false) {
return;
}
Severity Tuning
Adjust severity per rule (e.g., warning instead of error) for gradual adoption:
<rule ref="ObjectCalisthenics.Sniffs.NamingConventions.NoGetterSetterMethodsSniff">
<severity>3</severity> <!-- Warning -->
</rule>
Laravel Artisan Integration
Create a custom Artisan command to run phpcs with Laravel’s bootstrapped environment:
// app/Console/Commands/RunCalisthenics.php
public function handle() {
$this->call('phpcs', [
'--standard' => base_path('vendor/instaclick/object-calisthenics-sniffs/ruleset.xml'),
'app/'
]);
}
How can I help you explore Laravel packages today?