Skip to content

Commit 818d7d2

Browse files
Initial commit
0 parents  commit 818d7d2

18 files changed

+2450
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/bin/
2+
/vendor/
3+
.idea

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Florian Krämer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# PHPStan Rules
2+
3+
Additional rules for PHPStan. Mostly focused on clean code and architecture.
4+
5+
## Usage
6+
7+
```bash
8+
composer require/phauthentic/phpstan-rules --dev
9+
```
10+
11+
## Rules
12+
13+
Add them to your `phpstan.neon` configuration file under the section `services`.
14+
15+
### Control Structure Nesting Rule
16+
17+
Ensures that the nesting level of `if` and `try-catch` statements does not exceed a specified limit.
18+
19+
**Configuration Example:**
20+
```neon
21+
-
22+
class: Phauthentic\PhpstanRules\ControlStructureNestingRule
23+
arguments:
24+
maxNestingLevel: 2
25+
tags:
26+
- phpstan.rules.rule
27+
```
28+
29+
### Too Many Arguments Rule
30+
31+
Checks that methods do not have more than a specified number of arguments.
32+
33+
**Configuration Example:**
34+
```neon
35+
-
36+
class: Phauthentic\PhpstanRules\TooManyArgumentsRule
37+
arguments:
38+
maxArguments: 3
39+
tags:
40+
- phpstan.rules.rule
41+
```
42+
### Readonly Class Rule
43+
44+
Ensures that classes matching specified patterns are declared as `readonly`.
45+
46+
**Configuration Example:**
47+
```neon
48+
-
49+
class: Phauthentic\PhpstanRules\ReadonlyClassRule
50+
arguments:
51+
patterns: ['/^App\\Controller\\/']
52+
tags:
53+
- phpstan.rules.rule
54+
```
55+
56+
### Dependency Constraints Rule
57+
58+
Enforces dependency constraints between namespaces by checking `use` statements.
59+
60+
The constructor takes an array of namespace dependencies. The key is the namespace that should not depend on the namespaces in the array of values.
61+
62+
In the example below nothing from `App\Domain` can depend on anything from `App\Controller`.
63+
64+
**Configuration Example:**
65+
```neon
66+
-
67+
class: Phauthentic\PhpstanRules\DependencyConstraintsRule
68+
arguments:
69+
namespaceDependencies: [
70+
'App\\Domain\\': ['/^App\\Controller\\/']
71+
]
72+
tags:
73+
- phpstan.rules.rule
74+
```
75+
76+
## License
77+
78+
This library is under the MIT license.
79+
80+
Copyright Florian Krämer

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "phauthentic/phpstan-rules",
3+
"type": "library",
4+
"require-dev": {
5+
"phpstan/phpstan": "^2.1",
6+
"phpunit/phpunit": "^12.0",
7+
"squizlabs/php_codesniffer": "^3.12"
8+
},
9+
"autoload": {
10+
"psr-4": {
11+
"Phauthentic\\PhpstanRules\\": "src/"
12+
}
13+
},
14+
"authors": [
15+
{
16+
"name": "Florian Krämer"
17+
}
18+
],
19+
"config": {
20+
"bin-dir": "bin"
21+
}
22+
}

0 commit comments

Comments
 (0)