drop html from RectorRecipe, buggy and confusing, handle manually (#4199)

This commit is contained in:
Tomas Votruba 2020-09-11 16:08:19 +02:00 committed by GitHub
parent a6444fb801
commit 42f377c825
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 29 deletions

View File

@ -46,7 +46,7 @@ final class TemplateFinder
$filePaths = $this->addRuleAndTestCase($rectorRecipe, $filePaths);
/** @var string[] $filePaths */
$filePaths[] = $this->resolveFixtureFilePath($rectorRecipe->isPhpSnippet());
$filePaths[] = $this->resolveFixtureFilePath();
$this->ensureFilePathsExists($filePaths);
@ -85,14 +85,9 @@ final class TemplateFinder
return $filePaths;
}
private function resolveFixtureFilePath(bool $isPhpSnippet): string
private function resolveFixtureFilePath(): string
{
if ($isPhpSnippet) {
return __DIR__ . '/../../templates/rules/__package__/tests/Rector/__Category__/__Name__/Fixture/fixture.php.inc';
}
// is html snippet
return __DIR__ . '/../../templates/rules/__package__/tests/Rector/__Category__/__Name__/Fixture/html_fixture.php.inc';
return __DIR__ . '/../../templates/rules/__package__/tests/Rector/__Category__/__Name__/Fixture/fixture.php.inc';
}
/**

View File

@ -43,11 +43,6 @@ final class RectorRecipe
*/
private $isRectorRepository = false;
/**
* @var bool
*/
private $isPhpSnippet = true;
/**
* @var string
*/
@ -182,11 +177,6 @@ final class RectorRecipe
return $this->extraFileContent;
}
public function isPhpSnippet(): bool
{
return $this->isPhpSnippet;
}
public function isRectorRepository(): bool
{
return $this->isRectorRepository;
@ -293,8 +283,6 @@ final class RectorRecipe
private function setCodeBefore(string $codeBefore): void
{
$this->detectIsPhpSnippet($codeBefore);
$this->codeBefore = $this->normalizeCode($codeBefore);
}
@ -311,12 +299,6 @@ final class RectorRecipe
$this->category = (string) Strings::after($nodeTypes[0], '\\', -1);
}
private function detectIsPhpSnippet(string $codeBefore): void
{
// dummy yet effective way to detect PHP snippet from HTML
$this->isPhpSnippet = Strings::startsWith($codeBefore, '<?php') || Strings::match($codeBefore, '#^class #ms');
}
private function normalizeCode(string $code): string
{
if (Strings::startsWith($code, '<?php')) {