Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
Expand Down Expand Up @@ -49,7 +50,7 @@ public function getRuleDefinition(): RuleDefinition

final class SomeClass
{
private $items;
private ?Collection $items = null;

public function setItems(?Collection $items): void
{
Expand All @@ -63,7 +64,7 @@ public function setItems(?Collection $items): void

final class SomeClass
{
private $items;
private Collection $items;

public function setItems(Collection $items): void
{
Expand All @@ -79,19 +80,38 @@ public function setItems(Collection $items): void

public function getNodeTypes(): array
{
return [ClassMethod::class, Property::class];
return [Class_::class];
}

/**
* @param ClassMethod|Property $node
* @param Class_ $node
*/
public function refactor(Node $node): ClassMethod|Property|null
public function refactor(Node $node): ?Class_
{
if ($node instanceof Property) {
return $this->refactorProperty($node);
// nullable might be on purpose, e.g. via data provider
if ($this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}

$hasChanged = false;

foreach ($node->getMethods() as $classMethod) {
if ($this->refactorClassMethod($classMethod) instanceof ClassMethod) {
$hasChanged = true;
}
}

foreach ($node->getProperties() as $property) {
if ($this->refactorProperty($property) instanceof Property) {
$hasChanged = true;
}
}

return $this->refactorClassMethod($node);
if ($hasChanged) {
return $node;
}

return null;
}

private function refactorClassMethod(ClassMethod $classMethod): null|ClassMethod
Expand All @@ -100,11 +120,6 @@ private function refactorClassMethod(ClassMethod $classMethod): null|ClassMethod
return null;
}

// nullable might be on purpose, e.g. via data provider
if ($this->testsNodeAnalyzer->isInTestClass($classMethod)) {
return null;
}

$hasChanged = false;

foreach ($classMethod->params as $param) {
Expand Down
Loading