kubawerlos/php-cs-fixer-custom-fixers
Custom fixers for FriendsOfPHP PHP-CS-Fixer. Install via Composer, register the Fixers set, then enable individual rules to enforce additional style conventions (e.g., prefer class constants, remove leading global namespace slashes, tidy PHPDoc params).
PhpdocNoIncorrectVarAnnotationFixer addresses asymmetric-visibility property annotations in PHPDoc, a critical pain point in Laravel projects where visibility modifiers (e.g., protected/private properties with var) often violate PSR-12 standards. This aligns with Laravel’s emphasis on strict typing (e.g., PHP 8.1+ properties) and clean documentation.NoUnusedUsesFixer), this targets documentation consistency, reducing risk of unintended refactoring.$app->make()) or magic methods (e.g., __get()) may trigger unnecessary fixes.--dry-run and exclude paths (e.g., vendor/, tests/) in config:
'kubawerlos_phpdoc_no_incorrect_var_annotation' => [
'exclude' => ['tests/Feature/', 'vendor/'],
]
@mixin, @template) may not be handled perfectly.@phpstan-ignore-next-line.php-cs-fixer fix --profile --diff
NoUnusedUsesFixer) or log warnings?- run: php-cs-fixer fix --rules=kubawerlos_phpdoc_no_incorrect_var_annotation --allow-risky=yes --diff
laravel/breeze)?@var in PHP 8.2)?php-cs-fixer extension.phpstan/extension-installer to auto-fix PHPDoc issues in CI.rector/rector for broader PHP 8.x migrations.php-cs-fixer fix --dry-run --diff --rules=kubawerlos_phpdoc_no_incorrect_var_annotation
app/Providers/AppServiceProvider.php)..php-cs-fixer.dist.php).return PhpCsFixer\Config::create()
->setRules([
'kubawerlos_phpdoc_no_incorrect_var_annotation' => true,
// Exclude legacy tests
'exclude' => ['tests/Unit/OldTests/'],
]);
framework/src/Illuminate/Foundation/) for edge cases.laravel/sanctum) to catch PHPDoc inconsistencies./** @var protected string */ → /** @property string $property */).@phpstan-ignore-next-line).@mixin)."kubawerlos/php-cs-fixer-custom-fixers": "^3.37.2"
laravel-config) to avoid forked setups.--allow-risky=yes cautiously (this fixer is marked "risky" due to PHPDoc complexity).- /** @var protected string $name */
+ /** @property string $name */
Illuminate\Support\Traits\ForwardsCalls).app/, packages/) to reduce memory usage.php-cs-fixer fix --cache-file=.php-cs-fixer.cache
--parallel in CI for faster execution:
php-cs-fixer fix --parallel --rules=kubawerlos_phpdoc_no_incorrect_var_annotation
| Risk | Mitigation |
|---|---|
| Over-aggressive PHPDoc fixes | Exclude paths or use @phpstan-ignore-next-line for edge cases. |
| CI flakiness | Cache dependencies and use composer install --no-dev in CI. |
| False positives in legacy code | Test against a staging environment before enforcing in PR checks. |
| PHPDoc parser regressions | Downgrade to v3.37.1 if issues arise (check changelog). |
@property vs. @var.How can I help you explore Laravel packages today?