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
8 changes: 7 additions & 1 deletion src/Collector/NewWithFollowingSettersCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;
use Symfony\Component\HttpKernel\Kernel;
use Symplify\PHPStanRules\Enum\SymfonyClass;
use Webmozart\Assert\Assert;

/**
Expand All @@ -47,7 +48,12 @@
/**
* @var string[]
*/
private const array EXCLUDED_CLASSES = [Kernel::class];
private const array EXCLUDED_CLASSES = [
Kernel::class,
// controllers use setContainer() by Symfony design
SymfonyClass::ABSTRACT_CONTROLLER,
SymfonyClass::CONTROLLER,
];

public function __construct(
private ReflectionProvider $reflectionProvider,
Expand Down
22 changes: 22 additions & 0 deletions tests/Rules/NewOverSettersRule/Fixture/SkipController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Symplify\PHPStanRules\Tests\Rules\NewOverSettersRule\Fixture;

use Symplify\PHPStanRules\Tests\Rules\NewOverSettersRule\Source\SomeController;

final class SkipController
{
public function first()
{
$someController = new SomeController();
$someController->setContainer('some_container');
}

public function second()
{
$someController = new SomeController();
$someController->setContainer('some_container');
}
}
1 change: 1 addition & 0 deletions tests/Rules/NewOverSettersRule/NewOverSettersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static function provideData(): Iterator
yield [__DIR__ . '/Fixture/SkipCalledOnlyOnce.php', []];

yield [__DIR__ . '/Fixture/SkipSomeKernel.php', []];
yield [__DIR__ . '/Fixture/SkipController.php', []];
yield [__DIR__ . '/Fixture/SkipEntity.php', []];
yield [__DIR__ . '/Fixture/SkipAttributeEntity.php', []];
yield [__DIR__ . '/Fixture/SkipNotSetterCall.php', []];
Expand Down
11 changes: 11 additions & 0 deletions tests/Rules/NewOverSettersRule/Source/SomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Symplify\PHPStanRules\Tests\Rules\NewOverSettersRule\Source;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

final class SomeController extends AbstractController
{
}
Loading