Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2801,6 +2801,55 @@ public function __construct(

<br>

### NoServiceJugglingRule

A service injected in `__construct()` or an `autowire*()` method must not be passed to another method of the same class. The called method has its own constructor, so it can take the service directly instead of receiving it through a parameter list.

```yaml
rules:
- Symplify\PHPStanRules\Rules\Symfony\NoServiceJugglingRule
```

```php
public function run(): void
{
$this->handle($this->userHelper);
}

public function handle(UserHelper $userHelper): void
{
}
```

:x:

<br>

```php
public function __construct(
private readonly UserHelper $userHelper,
) {
}

public function run(): void
{
$this->handle();
}

public function handle(): void
{
// use $this->userHelper directly
}
```

:+1:

<br>

---

<br>

## 4. PHPUnit-specific Rules

### NoAssertFuncCallInTestsRule
Expand Down
1 change: 1 addition & 0 deletions config/symfony-rules.neon
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rules:
- Symplify\PHPStanRules\Rules\Symfony\RequireRouteNameToGenerateControllerRouteRule

# dependency injection
- Symplify\PHPStanRules\Rules\Symfony\NoServiceJugglingRule
- Symplify\PHPStanRules\Rules\Symfony\NoGetInControllerRule
- Symplify\PHPStanRules\Rules\Symfony\NoGetInCommandRule
- Symplify\PHPStanRules\Rules\Symfony\NoGetDoctrineInControllerRule
Expand Down
2 changes: 2 additions & 0 deletions src/Enum/RuleIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@ final class RuleIdentifier
public const string NO_PROPERTY_TO_PROPERTY_ASSIGN = 'symplify.noPropertyToPropertyAssign';

public const string REQUIRE_ARRAY_SHAPE_RETURN = 'symplify.requireArrayShapeReturn';

public const string NO_SERVICE_JUGGLING = 'symplify.noServiceJuggling';
}
Loading
Loading