Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Psr2R Sniffer

Psr2R Sniffer Laravel Package

fig-r/psr2r-sniffer

PHP_CodeSniffer ruleset implementing PSR-2-R for PHP 8.1+ projects. Includes 190+ sniffs, supports CI, and can auto-fix many issues via phpcbf. Install with Composer and reference the bundled PSR2R ruleset in phpcs.xml.

View on GitHub
Deep Wiki
Context7

A PSR-2-R code sniffer and code-style auto-correction-tool - including many useful additions

Frequently asked questions about Psr2R Sniffer
How do I install PSR-2-R Sniffer in a Laravel project?
Run `composer require --dev fig-r/psr2r-sniffer` in your Laravel project root. No additional Laravel-specific setup is needed beyond adding a `phpcs.xml` file referencing the bundled ruleset.
Does this package work with Laravel 8.x or older?
No, PSR-2-R Sniffer requires PHP 8.1+, which aligns with Laravel 9+. For Laravel 8.x, consider alternatives like `php-cs-fixer` with PSR-12 rules or upgrade your Laravel version.
Can I auto-fix code style issues in Laravel using this package?
Yes, use `phpcbf` (PHP Code Beauty Fix) to auto-correct supported violations. Run it via `vendor/bin/phpcbf` in your project root or target specific files/directories.
How do I configure PSR-2-R Sniffer to ignore Laravel-specific code like magic methods?
Edit your `phpcs.xml` to exclude sniffs conflicting with Laravel’s conventions. For example, exclude `PSR2.Classes.PropertyDeclaration.Underscore` for magic properties or add path exclusions like `<exclude-pattern>app/Providers/*</exclude-pattern>`.
Will this package slow down my Laravel CI pipeline?
Running 230+ sniffs may impact performance, especially for large codebases. Mitigate this by excluding non-critical paths (e.g., `vendor/`, `storage/`) or running sniffs in parallel using tools like `php-parallel-lint`.
How does PSR-2-R Sniffer differ from `pint` or `php-cs-fixer`?
PSR-2-R Sniffer enforces stricter PSR-2-R rules (including PHP 8.1+ features like enums) and provides granular sniffs, while `pint` is a formatter focused on auto-fixing. Avoid redundancy by disabling overlapping rules in `phpcs.xml` (e.g., whitespace sniffs if `pint` handles them).
Can I integrate this with Laravel’s Artisan for custom commands?
Yes, create a custom Artisan command to run sniffs or auto-fixes. Register it in a service provider and call it via `php artisan`. Example: `php artisan psr2r:fix` to auto-correct issues in the `app/` directory.
How do I handle false positives, like Laravel’s dynamic Facades (e.g., `Route::`)?
Exclude specific sniffs or paths in `phpcs.xml`. For Facades, disable sniffs like `DocBlockReturnSelfSniff` or use `<exclude-pattern>` to target problematic files. Test with `--sniffs=...` to isolate issues before full adoption.
Should I use PSR-2-R Sniffer alongside PHPStan or Psalm?
Yes, but configure them separately. PSR-2-R Sniffer focuses on code style, while static analyzers like PHPStan handle type safety. Run them in CI sequentially or use tools like `parallel-lint` to avoid conflicts.
How do I migrate from PSR-12 or `php-cs-fixer` to PSR-2-R Sniffer?
Start by running PSR-2-R Sniffer in a feature branch with a subset of sniffs (e.g., whitespace rules). Use `phpcbf` to auto-fix issues incrementally, then expand to stricter rules. Document the migration path for your team.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata