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

/**
Expand Down Expand Up @@ -76,6 +77,11 @@ public function processNode(Node $node, Scope $scope): ?array
return null;
}

// tests create objects and exercise their behavior, not configure them for construction
if (TestClassDetector::isTestClass($scope)) {
return null;
}

// basically all nodes that have ->stmts inside
if (! $node instanceof ClassMethod && ! $node instanceof Function_ && ! $node instanceof If_ && ! $node instanceof ElseIf_ && ! $node instanceof While_ && ! $node instanceof Foreach_ && ! $node instanceof For_) {
return null;
Expand Down
24 changes: 24 additions & 0 deletions tests/Rules/NewOverSettersRule/Fixture/SkipSetterContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

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

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

final class SkipSetterContext
{
public function first()
{
$alwaysSetters = new SomeObject();
$alwaysSetters->setName('John');
$alwaysSetters->setAge(25);
}

public function second()
{
$alwaysSetters = new SomeObject();
$alwaysSetters->setName('Doe');
$alwaysSetters->setAge(35);
}
}
1 change: 1 addition & 0 deletions tests/Rules/NewOverSettersRule/NewOverSettersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static function provideData(): Iterator
yield [__DIR__ . '/Fixture/SkipAttributeEntity.php', []];
yield [__DIR__ . '/Fixture/SkipNotSetterCall.php', []];
yield [__DIR__ . '/Fixture/SkipNoArgSetters.php', []];
yield [__DIR__ . '/Fixture/SkipSetterContext.php', []];
}

/**
Expand Down
Loading