wubbleyou / wubblestan
A set of prebuilt rules for Larastan/PHPStan
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:phpstan-extension
Requires (Dev)
- larastan/larastan: ^3.0
This package is auto-updated.
Last update: 2025-05-11 01:05:51 UTC
README
A simple set of prebuilt rules for PHPStan/Larastan.
Setup
Simply install this as you would any other composer package:
composer require --dev "wubbleyou/wubblestan"
Neon Config
Add the class definition to your services, this should be in a phpstan.neon
file in your project root. See Larastan - Getting Started if you're confused.
services:
- class: Wubbleyou\Wubblestan\Rules\RULE_CLASS
tags:
- phpstan.rules.rule
Whitelisting
We can just use PHPStans ignoring errors functionality to whitelist specific controllers/methods.
AuthorisationInController
This rule scans all controller methods and fails whenever one is detected without any authorisation - essentially checks if $this->authorize(...)
is present.
StandardRequestInController
This rule scans all controller methods to make sure the standard Laravel request class is not being used. We should always be creating a dedicated request class extending FormRequest
.
Any method using Illuminate\Http\Request
will fail.
ModelsInController
This rule scans all controller methods to make sure you're not using model classes directly within a controller. For an example the following is forbidden:
$user = User::find(2);
User::create([...])
BusinessLogicInController
This rule scans all controller methods to make sure no business logic is present - we should be using services instead. Currently it checks for usage of:
if
for
foreach
while
switch
MaxLengthController
This rule scans all controller methods to make sure none of them exceed a limit of 20 lines in length.
Example phpstan.neon config
Note: level should be set somewhere between 1 and 10.
includes:
- vendor/larastan/larastan/extension.neon
- vendor/nesbot/carbon/extension.neon
parameters:
paths:
- app/
level: 0-10
services:
- class: Wubbleyou\Wubblestan\Rules\BusinessLogicInController
tags:
- phpstan.rules.rule
- class: Wubbleyou\Wubblestan\Rules\ModelsInController
tags:
- phpstan.rules.rule
- class: Wubbleyou\Wubblestan\Rules\MaxLengthController
tags:
- phpstan.rules.rule
- class: Wubbleyou\Wubblestan\Rules\StandardRequestInController
tags:
- phpstan.rules.rule
- class: Wubbleyou\Wubblestan\Rules\AuthorisationInController
tags:
- phpstan.rules.rule