Skip to content

Commit

Permalink
Skip method of abstract class for StaticCallOnNonStaticToInstanceCall…
Browse files Browse the repository at this point in the history
…Rector. (#2938)
  • Loading branch information
Wohlie committed Sep 19, 2022
1 parent 4c69331 commit 35b0d39
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

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

use Rector\Tests\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector\Source\AbstractClassHello;

class SkipAbstractClassWorld extends AbstractClassHello
{
public function say()
{
parent::say();
echo "Wold!";
}
}

class SkipAbstractClassUniverse extends SkipAbstractClassWorld
{
public function say()
{
AbstractClassHello::say();
echo "Universe!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);

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

abstract class AbstractClassHello
{
public function say()
{
echo "Hello ";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@ private function shouldSkip(string $methodName, string $className, StaticCall $s
return true;
}

// does the method even exist?
$classReflection = $this->reflectionProvider->getClass($className);
if ($classReflection->isAbstract()) {
return true;
}

// does the method even exist?
if (! $classReflection->hasMethod($methodName)) {
return true;
}
Expand Down

0 comments on commit 35b0d39

Please sign in to comment.