@@ -155,7 +155,7 @@ Currently, you can check if a class:
155155### Depends on a namespace
156156
157157``` php
158- $rules = Rule::allClasses()
158+ $rules[] = Rule::allClasses()
159159 ->that(new ResideInOneOfTheseNamespaces('App\Domain'))
160160 ->should(new DependsOnlyOnTheseNamespaces('App\Domain', 'Ramsey\Uuid'))
161161 ->because('we want to protect our domain from external dependencies except for Ramsey\Uuid');
@@ -164,7 +164,7 @@ $rules = Rule::allClasses()
164164### Doc block contains a string
165165
166166``` php
167- $rules = Rule::allClasses()
167+ $rules[] = Rule::allClasses()
168168 ->that(new ResideInOneOfTheseNamespaces('App\Domain\Events'))
169169 ->should(new ContainDocBlockLike('@psalm-immutable'))
170170 ->because('we want to enforce immutability');
@@ -173,7 +173,7 @@ $rules = Rule::allClasses()
173173### Doc block not contains a string
174174
175175``` php
176- $rules = Rule::allClasses()
176+ $rules[] = Rule::allClasses()
177177 ->that(new ResideInOneOfTheseNamespaces('App\Controller'))
178178 ->should(new NotContainDocBlockLike('@psalm-immutable'))
179179 ->because('we don\'t want to enforce immutability');
@@ -182,16 +182,18 @@ $rules = Rule::allClasses()
182182### Extend another class
183183
184184``` php
185- $rules = Rule::allClasses()
185+ $rules[] = Rule::allClasses()
186186 ->that(new ResideInOneOfTheseNamespaces('App\Controller'))
187187 ->should(new Extend('App\Controller\AbstractController'))
188188 ->because('we want to be sure that all controllers extend AbstractController');
189+
190+ You can add multiple parameters, the violation will happen when none of them match
189191```
190192
191193### Has an attribute (requires PHP >= 8.0)
192194
193195``` php
194- $rules = Rule::allClasses()
196+ $rules[] = Rule::allClasses()
195197 ->that(new ResideInOneOfTheseNamespaces('App\Controller'))
196198 ->should(new HaveAttribute('AsController'))
197199 ->because('it configures the service container');
@@ -200,7 +202,7 @@ $rules = Rule::allClasses()
200202### Have a name matching a pattern
201203
202204``` php
203- $rules = Rule::allClasses()
205+ $rules[] = Rule::allClasses()
204206 ->that(new ResideInOneOfTheseNamespaces('App\Service'))
205207 ->should(new HaveNameMatching('*Service'))
206208 ->because('we want uniform naming for services');
@@ -209,7 +211,7 @@ $rules = Rule::allClasses()
209211### Implements an interface
210212
211213``` php
212- $rules = Rule::allClasses()
214+ $rules[] = Rule::allClasses()
213215 ->that(new ResideInOneOfTheseNamespaces('App\Controller'))
214216 ->should(new Implement('ContainerAwareInterface'))
215217 ->because('all controllers should be container aware');
@@ -218,7 +220,7 @@ $rules = Rule::allClasses()
218220### Not implements an interface
219221
220222``` php
221- $rules = Rule::allClasses()
223+ $rules[] = Rule::allClasses()
222224 ->that(new ResideInOneOfTheseNamespaces('App\Infrastructure\RestApi\Public'))
223225 ->should(new NotImplement('ContainerAwareInterface'))
224226 ->because('all public controllers should not be container aware');
@@ -227,7 +229,7 @@ $rules = Rule::allClasses()
227229### Is abstract
228230
229231``` php
230- $rules = Rule::allClasses()
232+ $rules[] = Rule::allClasses()
231233 ->that(new ResideInOneOfTheseNamespaces('App\Customer\Service'))
232234 ->should(new IsAbstract())
233235 ->because('we want to be sure that classes are abstract in a specific namespace');
@@ -236,7 +238,7 @@ $rules = Rule::allClasses()
236238### Is trait
237239
238240``` php
239- $rules = Rule::allClasses()
241+ $rules[] = Rule::allClasses()
240242 ->that(new ResideInOneOfTheseNamespaces('App\Customer\Service\Traits'))
241243 ->should(new IsTrait())
242244 ->because('we want to be sure that there are only traits in a specific namespace');
@@ -245,16 +247,25 @@ $rules = Rule::allClasses()
245247### Is final
246248
247249``` php
248- $rules = Rule::allClasses()
250+ $rules[] = Rule::allClasses()
249251 ->that(new ResideInOneOfTheseNamespaces('App\Domain\Aggregates'))
250252 ->should(new IsFinal())
251253 ->because('we want to be sure that aggregates are final classes');
252254```
253255
256+ ### Is readonly
257+
258+ ``` php
259+ $rules[] = Rule::allClasses()
260+ ->that(new ResideInOneOfTheseNamespaces('App\Domain\ValueObjects'))
261+ ->should(new IsReadonly())
262+ ->because('we want to be sure that value objects are readonly classes');
263+ ```
264+
254265### Is interface
255266
256267``` php
257- $rules = Rule::allClasses()
268+ $rules[] = Rule::allClasses()
258269 ->that(new ResideInOneOfTheseNamespaces('App\Interfaces'))
259270 ->should(new IsInterface())
260271 ->because('we want to be sure that all interfaces are in one directory');
@@ -263,7 +274,7 @@ $rules = Rule::allClasses()
263274### Is enum
264275
265276``` php
266- $rules = Rule::allClasses()
277+ $rules[] = Rule::allClasses()
267278 ->that(new ResideInOneOfTheseNamespaces('App\Enum'))
268279 ->should(new IsEnum())
269280 ->because('we want to be sure that all classes are enum');
@@ -272,7 +283,7 @@ $rules = Rule::allClasses()
272283### Is not abstract
273284
274285``` php
275- $rules = Rule::allClasses()
286+ $rules[] = Rule::allClasses()
276287 ->that(new ResideInOneOfTheseNamespaces('App\Domain'))
277288 ->should(new IsNotAbstract())
278289 ->because('we want to avoid abstract classes into our domain');
@@ -281,7 +292,7 @@ $rules = Rule::allClasses()
281292### Is not trait
282293
283294``` php
284- $rules = Rule::allClasses()
295+ $rules[] = Rule::allClasses()
285296 ->that(new ResideInOneOfTheseNamespaces('App\Domain'))
286297 ->should(new IsNotTrait())
287298 ->because('we want to avoid traits in our codebase');
@@ -290,16 +301,25 @@ $rules = Rule::allClasses()
290301### Is not final
291302
292303``` php
293- $rules = Rule::allClasses()
304+ $rules[] = Rule::allClasses()
294305 ->that(new ResideInOneOfTheseNamespaces('App\Infrastructure\Doctrine'))
295306 ->should(new IsNotFinal())
296307 ->because('we want to be sure that our adapters are not final classes');
297308```
298309
310+ ### Is not readonly
311+
312+ ``` php
313+ $rules[] = Rule::allClasses()
314+ ->that(new ResideInOneOfTheseNamespaces('App\Domain\Entity'))
315+ ->should(new IsNotReadonly())
316+ ->because('we want to be sure that there are no readonly entities');
317+ ```
318+
299319### Is not interface
300320
301321``` php
302- $rules = Rule::allClasses()
322+ $rules[] = Rule::allClasses()
303323 ->that(new ResideInOneOfTheseNamespaces('Tests\Integration'))
304324 ->should(new IsNotInterface())
305325 ->because('we want to be sure that we do not have interfaces in tests');
@@ -308,7 +328,7 @@ $rules = Rule::allClasses()
308328### Is not enum
309329
310330``` php
311- $rules = Rule::allClasses()
331+ $rules[] = Rule::allClasses()
312332 ->that(new ResideInOneOfTheseNamespaces('App\Controller'))
313333 ->should(new IsNotEnum())
314334 ->because('we want to be sure that all classes are not enum');
@@ -317,7 +337,7 @@ $rules = Rule::allClasses()
317337### Not depends on a namespace
318338
319339``` php
320- $rules = Rule::allClasses()
340+ $rules[] = Rule::allClasses()
321341 ->that(new ResideInOneOfTheseNamespaces('App\Application'))
322342 ->should(new NotDependsOnTheseNamespaces('App\Infrastructure'))
323343 ->because('we want to avoid coupling between application layer and infrastructure layer');
@@ -326,25 +346,27 @@ $rules = Rule::allClasses()
326346### Not extend another class
327347
328348``` php
329- $rules = Rule::allClasses()
349+ $rules[] = Rule::allClasses()
330350 ->that(new ResideInOneOfTheseNamespaces('App\Controller\Admin'))
331351 ->should(new NotExtend('App\Controller\AbstractController'))
332352 ->because('we want to be sure that all admin controllers not extend AbstractController for security reasons');
353+
354+ You can add multiple parameters, the violation will happen when one of them match
333355```
334356
335357### Don't have dependency outside a namespace
336358
337359``` php
338- $rules = Rule::allClasses()
360+ $rules[] = Rule::allClasses()
339361 ->that(new ResideInOneOfTheseNamespaces('App\Domain'))
340- ->should(new NotHaveDependencyOutsideNamespace('App\Domain', ['Ramsey\Uuid']))
362+ ->should(new NotHaveDependencyOutsideNamespace('App\Domain', ['Ramsey\Uuid'], true ))
341363 ->because('we want protect our domain except for Ramsey\Uuid');
342364```
343365
344366### Not have a name matching a pattern
345367
346368``` php
347- $rules = Rule::allClasses()
369+ $rules[] = Rule::allClasses()
348370 ->that(new ResideInOneOfTheseNamespaces('App'))
349371 ->should(new NotHaveNameMatching('*Manager'))
350372 ->because('*Manager is too vague in naming classes');
@@ -353,7 +375,7 @@ $rules = Rule::allClasses()
353375### Reside in a namespace
354376
355377``` php
356- $rules = Rule::allClasses()
378+ $rules[] = Rule::allClasses()
357379 ->that(new HaveNameMatching('*Handler'))
358380 ->should(new ResideInOneOfTheseNamespaces('App\Application'))
359381 ->because('we want to be sure that all CommandHandlers are in a specific namespace');
@@ -363,9 +385,9 @@ $rules = Rule::allClasses()
363385### Not reside in a namespace
364386
365387``` php
366- $rules = Rule::allClasses()
388+ $rules[] = Rule::allClasses()
367389 ->that(new Extend('App\Domain\Event'))
368- ->should(new NotResideInOneOfTheseNamespaces ('App\Application', 'App\Infrastructure'))
390+ ->should(new NotResideInTheseNamespaces ('App\Application', 'App\Infrastructure'))
369391 ->because('we want to be sure that all events not reside in wrong layers');
370392```
371393
0 commit comments