@@ -264,6 +264,55 @@ abstract class ParentClass
264264
265265<br >
266266
267+ ### ForbiddenNewArgumentRule
268+
269+ Type "%s" is forbidden to be created manually with ` new X() ` . Use service and constructor injection instead
270+
271+ ``` yaml
272+ services :
273+ -
274+ class : Symplify\PHPStanRules\Rules\ForbiddenNewArgumentRule
275+ tag : [phpstan.rules.rule]
276+ arguments :
277+ forbiddenTypes :
278+ - RepositoryService
279+ ` ` `
280+
281+ ↓
282+
283+ ` ` ` php
284+ class SomeService
285+ {
286+ public function run()
287+ {
288+ $repositoryService = new RepositoryService();
289+ $item = $repositoryService->get(1);
290+ }
291+ }
292+ ```
293+
294+ :x :
295+
296+ <br >
297+
298+ ``` php
299+ class SomeService
300+ {
301+ public function __construct(private RepositoryService $repositoryService)
302+ {
303+ }
304+
305+ public function run()
306+ {
307+ $item = $this->repositoryService->get(1);
308+ }
309+ }
310+ ```
311+
312+ :+1 :
313+
314+ <br >
315+
267316### ForbiddenFuncCallRule
268317
269318Function ` "%s()" ` cannot be used/left in the code
@@ -963,6 +1012,17 @@ final class SomeClass
9631012
9641013## 2. Doctrine-specific Rules
9651014
1015+ ### RequireQueryBuilderOnRepositoryRule
1016+
1017+ Prevents using ` $entityManager->createQueryBuilder('...') ` , use ` $repository->createQueryBuilder() ` as safer.
1018+
1019+ ``` yaml
1020+ rules :
1021+ - Symplify\PHPStanRules\Rules\Doctrine\RequireQueryBuilderOnRepositoryRule
1022+ ` ` `
1023+
1024+ <br>
1025+
9661026### NoGetRepositoryOutsideServiceRule
9671027
9681028Instead of getting repository from EntityManager, use constructor injection and service pattern to keep code clean
@@ -1082,6 +1142,29 @@ final class SomeFixture extends AbstractFixture
10821142
10831143## 3. Symfony-specific Rules
10841144
1145+ ### NoGetDoctrineInControllerRule
1146+
1147+ Prevents using ` $this->getDoctrine() ` in controllers, to promote dependency injection.
1148+
1149+ ``` yaml
1150+ rules :
1151+ - Symplify\PHPStanRules\Rules\Symfony\NoGetDoctrineInControllerRule
1152+ ` ` `
1153+
1154+ <br>
1155+
1156+ ### NoGetInControllerRule
1157+
1158+ Prevents using ` $this->get(...)` in controllers, to promote dependency injection.
1159+
1160+ ` ` ` yaml
1161+ rules:
1162+ - Symplify\P HPStanRules\R ules\S ymfony\N oGetInControllerRule
1163+ ` ` `
1164+
1165+ <br>
1166+
1167+
10851168# ## NoAbstractControllerConstructorRule
10861169
10871170Abstract controller should not have constructor, as it can lead to tight coupling. Use @required annotation instead
0 commit comments