Skip to content

Commit 3d3500a

Browse files
authored
feat: improve conditional tags (#197)
1 parent a49e4b0 commit 3d3500a

File tree

2 files changed

+60
-40
lines changed

2 files changed

+60
-40
lines changed

README.md

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,47 @@ composer require --dev canvural/larastan-strict-rules
1616

1717
To enable all the rules, include `rules.neon` in your project's PHPStan config:
1818

19-
```
19+
```neon
2020
includes:
2121
- vendor/canvural/larastan-strict-rules/rules.neon
2222
```
2323

24+
## Disabling rules
25+
26+
You can disable rules using configuration parameters:
27+
28+
```neon
29+
parameters:
30+
larastanStrictRules:
31+
noDynamicWhere: false
32+
noFacade: false
33+
noGlobalLaravelFunction: false
34+
noLocalQueryScope: false
35+
noPropertyAccessor: false
36+
noValidationInController: false
37+
scopeShouldReturnQueryBuilder: false
38+
listenerShouldHaveVoidReturnType: false
39+
```
2440

2541
## Enabling rules one-by-one
26-
If you don't want to start using all the available strict rules at once but only one or two, you can! Just don't include the whole `rules.neon` from this package in your configuration, but look at its contents and copy only the rules you want to your configuration under the `services` key. For example:
2742

43+
If you don't want to start using all the available strict rules at once but only one or two, you can!
44+
45+
You can disable all rules from the included `rules.neon` with:
46+
47+
```neon
48+
parameters:
49+
larastanStrictRules:
50+
allRules: false
2851
```
29-
services:
30-
-
31-
class: Vural\LarastanStrictRules\Rules\NoDynamicWhereRule
32-
tags:
33-
- phpstan.rules.rule
34-
-
35-
class: Vural\LarastanStrictRules\Rules\NoFacadeRule
36-
tags:
37-
- phpstan.rules.rule
52+
53+
Then you can re-enable individual rules with configuration parameters:
54+
55+
```neon
56+
parameters:
57+
larastanStrictRules:
58+
allRules: false
59+
noDynamicWhere: true
3860
```
3961

4062
## Rules
@@ -51,14 +73,12 @@ This rule disallows the usage of Laravel Facades. Also, checks for the real time
5173

5274
This rule disallows the usage of global helper functions that comes with Laravel.
5375

54-
If you want to allow some functions, you can use the `allowedFunctions` parameter for this rule. Like so:
76+
If you want to allow some functions, you can use the `allowedGlobalFunctions` parameter. Like so:
5577
```neon
56-
-
57-
class: Vural\LarastanStrictRules\Rules\NoGlobalLaravelFunctionRule
58-
arguments:
59-
allowedFunctions:
60-
- app
61-
- event
78+
parameters:
79+
allowedGlobalFunctions:
80+
- app
81+
- event
6282
```
6383

6484
#### `NoValidationInControllerRule`
@@ -85,12 +105,10 @@ If you return `false` from an event listener, Laravel will stop the propagation
85105

86106
You need to configure this rule by adding the directories that your event listeners are in to the `listenerPaths` parameter:
87107
```neon
88-
-
89-
class: Vural\LarastanStrictRules\Rules\ListenerShouldHaveVoidReturnTypeRule
90-
arguments:
91-
listenerPaths:
92-
- app/Listeners
93-
- app/DomainA/Listeners
108+
parameters:
109+
listenerPaths:
110+
- app/Listeners
111+
- app/DomainA/Listeners
94112
```
95113

96114
## Changelog

rules.neon

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
parameters:
22
larastanStrictRules:
3-
noDynamicWhere: true
4-
noFacade: true
5-
noGlobalLaravelFunction: true
6-
noLocalQueryScope: false
7-
noPropertyAccessor: false
8-
noValidationInController: true
9-
scopeShouldReturnQueryBuilder: true
10-
listenerShouldHaveVoidReturnType: true
3+
allRules: true
4+
noDynamicWhere: %larastanStrictRules.allRules%
5+
noFacade: %larastanStrictRules.allRules%
6+
noGlobalLaravelFunction: %larastanStrictRules.allRules%
7+
noLocalQueryScope: %larastanStrictRules.allRules%
8+
noPropertyAccessor: %larastanStrictRules.allRules%
9+
noValidationInController: %larastanStrictRules.allRules%
10+
scopeShouldReturnQueryBuilder: %larastanStrictRules.allRules%
11+
listenerShouldHaveVoidReturnType: %larastanStrictRules.allRules%
1112
allowedGlobalFunctions: []
1213
listenerPaths: []
1314

1415
parametersSchema:
1516
larastanStrictRules: structure([
16-
noDynamicWhere: bool(),
17-
noFacade: bool(),
18-
noGlobalLaravelFunction: bool(),
19-
noLocalQueryScope: bool(),
20-
noPropertyAccessor: bool(),
21-
noValidationInController: bool(),
22-
scopeShouldReturnQueryBuilder: bool(),
23-
listenerShouldHaveVoidReturnType: bool(),
17+
allRules: anyOf(bool(), arrayOf(bool())),
18+
noDynamicWhere: anyOf(bool(), arrayOf(bool())),
19+
noFacade: anyOf(bool(), arrayOf(bool())),
20+
noGlobalLaravelFunction: anyOf(bool(), arrayOf(bool())),
21+
noLocalQueryScope: anyOf(bool(), arrayOf(bool())),
22+
noPropertyAccessor: anyOf(bool(), arrayOf(bool())),
23+
noValidationInController: anyOf(bool(), arrayOf(bool())),
24+
scopeShouldReturnQueryBuilder: anyOf(bool(), arrayOf(bool())),
25+
listenerShouldHaveVoidReturnType: anyOf(bool(), arrayOf(bool())),
2426
])
2527
allowedGlobalFunctions: listOf(string())
2628
listenerPaths: listOf(string())

0 commit comments

Comments
 (0)