canvural / larastan-strict-rules
Extra strict and opinionated PHPStan rules for Laravel.
Fund package maintenance!
canvural
www.paypal.me/canvural
Installs: 589 179
Dependents: 2
Suggesters: 0
Security: 0
Stars: 75
Watchers: 3
Forks: 5
Open Issues: 3
Type:phpstan-extension
Requires
- php: ^8.2
- larastan/larastan: ^3.0
- phpstan/phpstan: ^2.0
Requires (Dev)
- doctrine/coding-standard: ^12.0
- orchestra/testbench: ^9.0
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^10.0
- roave/security-advisories: dev-latest
- 3.0.x-dev
- 3.0.0
- 2.2.x-dev
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.x-dev
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1
- dev-master / 2.0.x-dev
- v2.0.2
- v2.0.1
- v2.0.0
- 1.x-dev
- 1.0.0
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-dependabot/composer/orchestra/testbench-tw-9.8.0
- dev-dependabot/composer/phpunit/phpunit-tw-11.5.1
This package is auto-updated.
Last update: 2024-12-16 04:41:12 UTC
README
Extra strict and opinionated PHPStan rules for Laravel.
Installation
You can install the package via composer:
composer require --dev canvural/larastan-strict-rules
To enable all the rules, include rules.neon
in your project's PHPStan config:
includes: - vendor/canvural/larastan-strict-rules/rules.neon
Disabling rules
You can disable rules using configuration parameters:
parameters: larastanStrictRules: noDynamicWhere: false noFacade: false noGlobalLaravelFunction: false noLocalQueryScope: false noPropertyAccessor: false noValidationInController: false scopeShouldReturnQueryBuilder: false listenerShouldHaveVoidReturnType: false
Enabling rules one-by-one
If you don't want to start using all the available strict rules at once but only one or two, you can!
You can disable all rules from the included rules.neon
with:
parameters: larastanStrictRules: allRules: false
Then you can re-enable individual rules with configuration parameters:
parameters: larastanStrictRules: allRules: false noDynamicWhere: true
Rules
NoDynamicWhereRule
This rule disallows the usage of dynamic where methods on Eloquent query builder.
NoFacadeRule
This rule disallows the usage of Laravel Facades. Also, checks for the real time facade usage.
NoGlobalLaravelFunctionRule
This rule disallows the usage of global helper functions that comes with Laravel.
If you want to allow some functions, you can use the allowedGlobalFunctions
parameter. Like so:
parameters: allowedGlobalFunctions: - app - event
NoValidationInControllerRule
This rule disallows validating the request in controllers.
ScopeShouldReturnQueryBuilderRule
This rule makes sure Illuminate\Database\Eloquent\Builder
instance is returned from Eloquent
local query scopes.
NoLocalQueryScopeRule
This rule disallows the usage of local model query scopes all together.
NoPropertyAccessorRule
This rule disallows the usage of model property accessors.
ListenerShouldHaveVoidReturnTypeRule
This rule makes sure your event listeners have a void return type.
If you return false
from an event listener, Laravel will stop the propagation of an event to other listeners. Sometimes this can be useful. But other time it can cause bugs that you will need to debug for hours. So this opinionated rule makes sure you always have void
return type for your event listeners.
You need to configure this rule by adding the directories that your event listeners are in to the listenerPaths
parameter:
parameters: listenerPaths: - app/Listeners - app/DomainA/Listeners
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
People:
License
The MIT License (MIT). Please see License File for more information.