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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Rector\Tests\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector\Fixture;

class SkipStaticClosureSameClassCall
{
public function boot(): void
{
// static closure — no $this, must not rewrite
$callback = static function (): void {
SkipStaticClosureSameClassCall::doWork();
};
}

public function doWork(): void
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Rector\Tests\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector\Fixture;

class SkipStaticMethodSameClassCall
{
public static function run(): string
{
// enclosing function is static — no $this, must not rewrite
return SkipStaticMethodSameClassCall::doWork();
}

public function doWork(): string
{
return 'work done';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public function refactor(Node $node): ?Node

$classReflection = $scope->getClassReflection();
if ($classReflection instanceof ClassReflection && $classReflection->getName() === $className) {
// detect any scope where $this is unavailable or possibly unavailable
if (! $scope->hasVariableType('this')->yes()) {
return null;
}

return new MethodCall(new Variable('this'), $node->name, $node->args);
}

Expand Down
Loading