@@ -7,6 +7,7 @@ Add them to your `phpstan.neon` configuration file under the section `services`.
77Ensures that the nesting level of ` if ` and ` try-catch ` statements does not exceed a specified limit.
88
99** Configuration Example:**
10+
1011``` neon
1112 -
1213 class: Phauthentic\PHPStanRules\CleanCode\ControlStructureNestingRule
@@ -21,6 +22,7 @@ Ensures that the nesting level of `if` and `try-catch` statements does not excee
2122Checks that methods do not have more than a specified number of arguments.
2223
2324** Configuration Example:**
25+
2426``` neon
2527 -
2628 class: Phauthentic\PHPStanRules\CleanCode\TooManyArgumentsRule
@@ -35,6 +37,7 @@ Checks that methods do not have more than a specified number of arguments.
3537Ensures that classes matching specified patterns are declared as ` readonly ` .
3638
3739** Configuration Example:**
40+
3841``` neon
3942 -
4043 class: Phauthentic\PHPStanRules\Architecture\ClassMustBeReadonlyRule
@@ -53,6 +56,7 @@ The constructor takes an array of namespace dependencies. The key is the namespa
5356In the example below nothing from ` App\Domain ` can depend on anything from ` App\Controller ` .
5457
5558** Configuration Example:**
59+
5660``` neon
5761 -
5862 class: Phauthentic\PHPStanRules\Architecture\DependencyConstraintsRule
@@ -69,6 +73,7 @@ In the example below nothing from `App\Domain` can depend on anything from `App\
6973Ensures that classes matching specified patterns are declared as ` final ` .
7074
7175** Configuration Example:**
76+
7277``` neon
7378 -
7479 class: Phauthentic\PHPStanRules\Architecture\ClassMustBeFinalRule
@@ -83,6 +88,7 @@ Ensures that classes matching specified patterns are declared as `final`.
8388Ensures that classes inside namespaces matching a given regex must have names matching at least one of the provided patterns.
8489
8590** Configuration Example:**
91+
8692``` neon
8793 -
8894 class: Phauthentic\PHPStanRules\Architecture\ClassnameMustMatchPatternRule
@@ -104,6 +110,7 @@ Ensures that classes inside namespaces matching a given regex must have names ma
104110Ensures that specific exception types are not caught in catch blocks. This is useful for preventing the catching of overly broad exception types like ` Exception ` , ` Error ` , or ` Throwable ` .
105111
106112** Configuration Example:**
113+
107114``` neon
108115 -
109116 class: Phauthentic\PHPStanRules\Architecture\CatchExceptionOfTypeNotAllowedRule
@@ -118,6 +125,7 @@ Ensures that specific exception types are not caught in catch blocks. This is us
118125Ensures that methods returning boolean values follow a specific naming convention. By default, boolean methods should start with ` is ` , ` has ` , ` can ` , ` should ` , ` was ` , or ` will ` .
119126
120127** Configuration Example:**
128+
121129``` neon
122130 -
123131 class: Phauthentic\PHPStanRules\Architecture\MethodsReturningBoolMustFollowNamingConventionRule
@@ -132,6 +140,7 @@ Ensures that methods returning boolean values follow a specific naming conventio
132140Ensures that methods matching a class and method name pattern have a specific signature, including parameter types, names, and count.
133141
134142** Configuration Example:**
143+
135144``` neon
136145 -
137146 class: Phauthentic\PHPStanRules\Architecture\MethodSignatureMustMatchRule
@@ -151,16 +160,18 @@ Ensures that methods matching a class and method name pattern have a specific si
151160 tags:
152161 - phpstan.rules.rule
153162```
163+
154164- ` pattern ` : Regex for ` ClassName::methodName ` .
155165- ` minParameters ` /` maxParameters ` : Minimum/maximum number of parameters.
156166- ` signature ` : List of expected parameter types and (optionally) name patterns.
157167- ` visibilityScope ` : Optional visibility scope (e.g., ` public ` , ` protected ` , ` private ` ).
158168
159169## Method Must Return Type Rule {#method-must-return-type-rule}
160170
161- Ensures that methods matching a class and method name pattern have a specific return type, nullability, or are void.
171+ Ensures that methods matching a class and method name pattern have a specific return type, nullability, or are void. Supports union types with "oneOf" and "allOf" configurations.
162172
163173** Configuration Example:**
174+
164175``` neon
165176 -
166177 class: Phauthentic\PHPStanRules\Architecture\MethodMustReturnTypeRule
@@ -182,13 +193,41 @@ Ensures that methods matching a class and method name pattern have a specific re
182193 pattern: '/^MyClass::reset$/'
183194 type: 'void'
184195 nullable: false
185- void: true
196+ void: false
197+ objectTypePattern: null
198+ -
199+ pattern: '/^MyClass::getValue$/'
200+ nullable: false
201+ void: false
202+ oneOf: ['int', 'string', 'bool']
203+ objectTypePattern: null
204+ -
205+ pattern: '/^MyClass::getUnionType$/'
206+ nullable: false
207+ void: false
208+ allOf: ['int', 'string']
209+ objectTypePattern: null
210+ -
211+ pattern: '/^MyClass::getAnyType$/'
212+ anyOf: ['object', 'void']
213+ objectTypePattern: null
214+ -
215+ pattern: '/^MyClass::getEntity$/'
216+ anyOf: ['regex:/^App\\Entity\\/', 'void']
186217 objectTypePattern: null
187218 tags:
188219 - phpstan.rules.rule
189220```
221+
190222- ` pattern ` : Regex for ` ClassName::methodName ` .
191- - ` type ` : Expected return type (` int ` , ` string ` , ` object ` , etc.).
223+ - ` type ` : Expected return type (` int ` , ` string ` , ` object ` , ` void ` , etc.). When using ` oneOf ` or ` allOf ` , this field is optional .
192224- ` nullable ` : Whether the return type must be nullable.
193- - ` void ` : Whether the method must return void.
225+ - ` void ` : Legacy field for void return types (use ` type: ' void' ` instead) .
194226- ` objectTypePattern ` : Regex for object return types (if ` type ` is ` object ` ).
227+ - ` oneOf ` : Array of types where one must match (for union types).
228+ - ` allOf ` : Array of types where all must be present in the union type.
229+ - ` anyOf ` : Alias for ` oneOf ` - array of types where one must match.
230+
231+ ** Regex Support** : You can use regex patterns in ` oneOf ` , ` allOf ` , and ` anyOf ` arrays by prefixing them with ` regex: ` . For example:
232+ - ` 'regex:/^App\\Entity\\/' ` - matches any class starting with "App\Entity\"
233+ - ` 'regex:/^UserEntity$/' ` - matches exactly "UserEntity"
0 commit comments