Skip to content

Commit 1de3740

Browse files
author
Florian Krämer
committed
Merged master
2 parents 173ee46 + 229a0c0 commit 1de3740

File tree

53 files changed

+1998
-602
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1998
-602
lines changed

README.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,28 @@ composer require phauthentic/phpstan-rules --dev
1414

1515
## Rules
1616

17-
See [Rules documentation](docs/Rules.md) for a list of available rules and configuration examples.
18-
19-
- Architecture Rules:
20-
- [Dependency Constraints Rule](docs/Rules.md#dependency-constraints-rule)
21-
- [Modular Architecture Rule](docs/Rules.md#modular-architecture-rule)
22-
- [Circular Module Dependency Rule](docs/Rules.md#circular-module-dependency-rule)
23-
- [Forbidden Namespaces Rule](docs/Rules.md#forbidden-namespaces-rule)
24-
- [Readonly Class Rule](docs/Rules.md#readonly-class-rule)
25-
- [Final Class Rule](docs/Rules.md#final-class-rule)
26-
- [Namespace Class Pattern Rule](docs/Rules.md#namespace-class-pattern-rule)
27-
- [Catch Exception of Type Not Allowed Rule](docs/Rules.md#catch-exception-of-type-not-allowed-rule)
28-
- [Methods Returning Bool Must Follow Naming Convention Rule](docs/Rules.md#methods-returning-bool-must-follow-naming-convention-rule)
29-
- [Method Signature Must Match Rule](docs/Rules.md#method-signature-must-match-rule)
30-
- [Method Must Return Type Rule](docs/Rules.md#method-must-return-type-rule)
31-
- Clean Code Rules:
32-
- [Control Structure Nesting Rule](docs/Rules.md#control-structure-nesting-rule)
33-
- [Too Many Arguments Rule](docs/Rules.md#too-many-arguments-rule)
34-
- [Max Line Length Rule](docs/Rules.md#max-line-length-rule)
17+
See individual rule documentation for detailed configuration examples. A [full configuration example](docs/Rules.md) is also available.
18+
19+
### Architecture Rules
20+
21+
- [Dependency Constraints Rule](docs/rules/Dependency-Constraints-Rule.md)
22+
- [Modular Architecture Rule](docs/rules/Modular-Architecture-Rule.md)
23+
- [Circular Module Dependency Rule](docs/rules/Circular-Module-Dependency-Rule.md)
24+
- [Forbidden Namespaces Rule](docs/rules/Forbidden-Namespaces-Rule.md)
25+
- [Class Must Be Readonly Rule](docs/rules/Class-Must-Be-Readonly-Rule.md)
26+
- [Class Must Be Final Rule](docs/rules/Class-Must-Be-Final-Rule.md)
27+
- [Classname Must Match Pattern Rule](docs/rules/Classname-Must-Match-Pattern-Rule.md)
28+
- [Catch Exception Of Type Not Allowed Rule](docs/rules/Catch-Exception-Of-Type-Not-Allowed-Rule.md)
29+
- [Class Must Have Specification Docblock Rule](docs/rules/Class-Must-Have-Specification-Docblock-Rule.md)
30+
- [Methods Returning Bool Must Follow Naming Convention Rule](docs/rules/Methods-Returning-Bool-Must-Follow-Naming-Convention-Rule.md)
31+
- [Method Signature Must Match Rule](docs/rules/Method-Signature-Must-Match-Rule.md)
32+
- [Method Must Return Type Rule](docs/rules/Method-Must-Return-Type-Rule.md)
33+
34+
### Clean Code Rules
35+
36+
- [Control Structure Nesting Rule](docs/rules/Control-Structure-Nesting-Rule.md)
37+
- [Too Many Arguments Rule](docs/rules/Too-Many-Arguments-Rule.md)
38+
- [Max Line Length Rule](docs/rules/Max-Line-Length-Rule.md)
3539

3640
### Using Regex in Rules
3741

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\SpecificationDocblock;
6+
7+
class InvalidMethodDocblockClass
8+
{
9+
/**
10+
* Specification:
11+
* This is missing the blank line and list items.
12+
*/
13+
public function testMethod(): void
14+
{
15+
}
16+
17+
public function otherMethod(): void
18+
{
19+
}
20+
}
21+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\SpecificationDocblock;
6+
7+
/**
8+
* Specification:
9+
*
10+
* - Removes an item from the recommendation engine
11+
* - Updates the cache accordingly
12+
*/
13+
class InvalidMissingPeriodsClass
14+
{
15+
public function execute(): void
16+
{
17+
}
18+
}
19+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\SpecificationDocblock;
6+
7+
/**
8+
* Specification:
9+
*
10+
* - Removes an item from the recommendation engine
11+
* and updates all related caches
12+
* - Validates the input data
13+
*/
14+
class InvalidMultiLineNoPeriodClass
15+
{
16+
public function execute(): void
17+
{
18+
}
19+
}
20+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\SpecificationDocblock;
6+
7+
/**
8+
* Specification:
9+
* - Missing blank line after header.
10+
*/
11+
class InvalidSpecificationNoBlankLineClass
12+
{
13+
public function execute(): void
14+
{
15+
}
16+
}
17+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\SpecificationDocblock;
6+
7+
/**
8+
* Specification:
9+
*
10+
* This has no list items.
11+
*/
12+
class InvalidSpecificationNoListItemClass
13+
{
14+
public function execute(): void
15+
{
16+
}
17+
}
18+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\SpecificationDocblock;
6+
7+
class MissingDocblockClass
8+
{
9+
public function execute(): void
10+
{
11+
}
12+
}
13+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\SpecificationDocblock;
6+
7+
class MissingMethodDocblockClass
8+
{
9+
public function testMethod(): void
10+
{
11+
}
12+
13+
public function otherMethod(): void
14+
{
15+
}
16+
}
17+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\SpecificationDocblock;
6+
7+
/**
8+
* This is just a regular docblock.
9+
*
10+
* - Some item here.
11+
*/
12+
class MissingSpecificationHeaderClass
13+
{
14+
public function execute(): void
15+
{
16+
}
17+
}
18+
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Specification Docblock Rule
2+
3+
This directory contains test data for the `ClassMustHaveSpecificationDocblockRule`.
4+
5+
## Rule Configuration Example
6+
7+
```neon
8+
# phpstan.neon
9+
services:
10+
-
11+
class: Phauthentic\PHPStanRules\Architecture\ClassMustHaveSpecificationDocblockRule
12+
arguments:
13+
patterns:
14+
- '/.*Facade$/' # All classes ending with "Facade"
15+
- '/.*Command$/' # All classes ending with "Command"
16+
- '/.*Handler$/' # All classes ending with "Handler"
17+
specificationHeader: 'Specification:' # Optional: customize the header
18+
requireBlankLineAfterHeader: true # Optional: require blank line (default: true)
19+
requireListItemsEndWithPeriod: false # Optional: require periods (default: false)
20+
tags:
21+
- phpstan.rules.rule
22+
```
23+
24+
## Configuration Options
25+
26+
- `patterns`: Array of regex patterns to match class names (required)
27+
- `specificationHeader`: Header text to look for (default: `'Specification:'`)
28+
- `requireBlankLineAfterHeader`: Require blank line after header (default: `true`)
29+
- `requireListItemsEndWithPeriod`: Require list items end with period (default: `false`)
30+
31+
## Valid Specification Format
32+
33+
### Minimum Required Format
34+
```php
35+
/**
36+
* Specification:
37+
*
38+
* - Removes an item from the recommendation engine.
39+
*/
40+
class MyClass {}
41+
```
42+
43+
### Multi-Line List Items
44+
List items can span multiple lines:
45+
```php
46+
/**
47+
* Specification:
48+
*
49+
* - Removes an item from the recommendation engine
50+
* and updates all related caches including user
51+
* preferences and global recommendations.
52+
* - Validates the input data before processing
53+
* and throws an exception if validation fails.
54+
*/
55+
class MyClass {}
56+
```
57+
58+
### With Annotations
59+
```php
60+
/**
61+
* Specification:
62+
*
63+
* - Removes an item from the recommendation engine.
64+
*
65+
* @throws \Exception
66+
*/
67+
class MyClass {}
68+
```
69+
70+
### With Additional Description and Annotations
71+
```php
72+
/**
73+
* Specification:
74+
*
75+
* - Removes an item from the recommendation engine.
76+
* - Updates the cache accordingly.
77+
*
78+
* Some additional description goes here.
79+
*
80+
* @throws \Exception
81+
* @return void
82+
*/
83+
class MyClass {}
84+
```
85+
86+
## Invalid Formats
87+
88+
### Missing Specification Header
89+
```php
90+
/**
91+
* This is just a regular docblock.
92+
*
93+
* - Some item here.
94+
*/
95+
class MyClass {} // ERROR
96+
```
97+
98+
### Missing Blank Line After Header
99+
```php
100+
/**
101+
* Specification:
102+
* - Missing blank line after header.
103+
*/
104+
class MyClass {} // ERROR
105+
```
106+
107+
### Missing List Items
108+
```php
109+
/**
110+
* Specification:
111+
*
112+
* This has no list items.
113+
*/
114+
class MyClass {} // ERROR
115+
```
116+

0 commit comments

Comments
 (0)