Skip to content

Commit 28a7d10

Browse files
committed
README
1 parent 8f8873f commit 28a7d10

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,49 @@ rules:
14381438
<br>
14391439

14401440

1441+
### TaggedIteratorOverRepeatedServiceCallRuleTest
1442+
1443+
Instead of repeated "->call(%s, ...)" calls, pass services as tagged iterator argument to the constructor
1444+
1445+
```yaml
1446+
rules:
1447+
- Symplify\PHPStanRules\Rules\Symfony\ConfigClosure\TaggedIteratorOverRepeatedServiceCallRule
1448+
```
1449+
1450+
```php
1451+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
1452+
use Symfony\Component\DependencyInjection\Loader\Configurator\ref;
1453+
1454+
return static function (ContainerConfigurator $containerConfigurator): void {
1455+
$services = $containerConfigurator->services();
1456+
1457+
$services->set(SomeService::class)
1458+
->call('setService', [ref('service1')])
1459+
->call('setService', [ref('service2')])
1460+
->call('setService', [ref('service3')]);
1461+
};
1462+
```
1463+
1464+
:x:
1465+
1466+
<br>
1467+
1468+
```php
1469+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
1470+
use Symfony\Component\DependencyInjection\Loader\Configurator\tagged_iterator;
1471+
1472+
return static function (ContainerConfigurator $containerConfigurator): void {
1473+
$services = $containerConfigurator->services();
1474+
1475+
$services->set(SomeService::class)
1476+
->arg('$services', tagged_iterator('SomeServiceTag'));
1477+
};
1478+
```
1479+
1480+
:+1:
1481+
1482+
<br>
1483+
14411484
### NoGetInCommandRule
14421485

14431486
Prevents using `$this->get(...)` in commands, to promote dependency injection.

src/Enum/SymfonyFunctionName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
final class SymfonyFunctionName
88
{
9-
public const REFERENCE = 'Symfony\Component\DependencyInjection\Loader\Configurator\reference';
9+
public const REFERENCE = 'Symfony\Component\DependencyInjection\Loader\Configurator\ref';
1010

1111
public const SERVICE = 'Symfony\Component\DependencyInjection\Loader\Configurator\service';
1212
}

src/Symfony/NodeFinder/RepeatedServiceAdderCallNameFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private static function findCallMethodCalls(MethodCall $methodCall): array
6666
$nodeFinder = new NodeFinder();
6767

6868
/** @var MethodCall[] $callMethodCalls */
69-
$callMethodCalls = $nodeFinder->find($methodCall, function (Node $node) {
69+
$callMethodCalls = $nodeFinder->find($methodCall, function (Node $node): bool {
7070
if (! $node instanceof MethodCall) {
7171
return false;
7272
}

0 commit comments

Comments
 (0)