File tree Expand file tree Collapse file tree 3 files changed +63
-1
lines changed
Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -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
Original file line number Diff line number Diff line change 22 - Symplify\PHPStanRules\Rules\Doctrine\NoGetRepositoryOutsideServiceRule
33 - Symplify\PHPStanRules\Rules\Doctrine\NoParentRepositoryRule
44 - Symplify\PHPStanRules\Rules\Doctrine\NoRepositoryCallInDataFixtureRule
5+
6+ # test fixtures
7+ - Symplify\PHPStanRules\Rules\Doctrine\RequireQueryBuilderOnRepositoryRule
Original file line number Diff line number Diff line change 66
77use PhpParser \Node ;
88use PhpParser \Node \Expr \MethodCall ;
9- use PhpParser \Node \Identifier ;
109use PHPStan \Analyser \Scope ;
1110use PHPStan \Reflection \ReflectionProvider ;
1211use PHPStan \Rules \Rule ;
You can’t perform that action at this time.
0 commit comments