[PHP 7.0] Fix variable name on static call

This commit is contained in:
TomasVotruba 2020-07-30 15:42:21 +02:00
parent 1796665137
commit 2ad011673f
5 changed files with 27 additions and 19 deletions

View File

@ -34,10 +34,8 @@ final class TemplateFileSystem
$destination = Strings::replace($destination, '#(__Configured|__Extra)#', '');
// remove ".inc" protection from PHPUnit if not a test case
if (! Strings::match($destination, '#/Fixture/#')) {
if (Strings::endsWith($destination, '.inc')) {
$destination = Strings::before($destination, '.inc');
}
if ($this->isNonFixtureFileWithIncSuffix($destination)) {
$destination = Strings::before($destination, '.inc');
}
return $targetDirectory . DIRECTORY_SEPARATOR . $destination;
@ -50,4 +48,13 @@ final class TemplateFileSystem
{
return str_replace(array_keys($variables), array_values($variables), $content);
}
private function isNonFixtureFileWithIncSuffix(string $filePath): bool
{
if (Strings::match($filePath, '#/Fixture/#')) {
return false;
}
return Strings::endsWith($filePath, '.inc');
}
}

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Rector\Php70\Rector\StaticCall;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\PropertyFetch;
@ -23,6 +24,7 @@ use ReflectionClass;
* @see https://3v4l.org/tQ32f
* @see https://3v4l.org/jB9jn
* @see https://stackoverflow.com/a/19694064/1348344
*
* @see \Rector\Php70\Tests\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector\StaticCallOnNonStaticToInstanceCallRectorTest
*/
final class StaticCallOnNonStaticToInstanceCallRector extends AbstractRector
@ -97,6 +99,10 @@ PHP
*/
public function refactor(Node $node): ?Node
{
if ($node->name instanceof Expr) {
return null;
}
$methodName = $this->getName($node->name);
$className = $this->resolveStaticCallClassName($node);

View File

@ -128,6 +128,11 @@ abstract class AbstractGenericRectorTestCase extends AbstractKernelTestCase
protected function tearDown(): void
{
$this->restoreOldParameterValues();
// restore PHP version if changed
if ($this->getPhpVersion() !== '') {
$this->setParameter(Option::PHP_VERSION_FEATURES, '10.0');
}
}
protected function getRectorClass(): string

View File

@ -28,16 +28,6 @@ abstract class AbstractRectorTestCase extends AbstractGenericRectorTestCase
*/
private $autoloadTestFixture = true;
protected function tearDown(): void
{
parent::tearDown();
// restore PHP version if changed
if ($this->getPhpVersion() !== '') {
$this->setParameter(Option::PHP_VERSION_FEATURES, '10.0');
}
}
protected function doTestFileInfoWithoutAutoload(SmartFileInfo $fileInfo): void
{
$this->autoloadTestFixture = false;
@ -136,6 +126,9 @@ abstract class AbstractRectorTestCase extends AbstractGenericRectorTestCase
}
}
/**
* @todo decouple to symplify/easy-testing
*/
private function updateFixtureContent(
SmartFileInfo $originalFileInfo,
string $changedContent,

View File

@ -53,11 +53,8 @@ final class ValidateFixtureContentCommand extends Command
// files content is equal, but it should not
$message = sprintf(
'The "%s" file has same content before "%s" and after it.%sRemove the content after "%s"',
$fixtureFileInfo->getRelativeFilePathFromCwd(),
SplitLine::REGEX,
PHP_EOL,
SplitLine::REGEX
'The "%s" file has same content before and after. Remove the 2nd half of the file.',
$fixtureFileInfo->getRelativeFilePathFromCwd()
);
$this->symfonyStyle->error($message);