Fix travis for Laravel self-run (#1398)

Fix travis for Laravel self-run
This commit is contained in:
Tomáš Votruba 2019-05-07 17:12:47 +02:00 committed by GitHub
commit fac1503915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

3
.gitignore vendored
View File

@ -12,3 +12,6 @@ composer.lock
create-rector.yaml
phpstan-dependencies.json
phpstan-paths.txt
# tests - travis
/laravel-dir

View File

@ -2,8 +2,6 @@
namespace Rector\CodeQuality\Rector\Array_;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
@ -11,8 +9,10 @@ use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\ClosureUse;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use Rector\NodeContainer\ParsedNodesByType;

View File

@ -100,12 +100,16 @@ final class FileProcessor
*/
public function printToString(SmartFileInfo $smartFileInfo): string
{
$this->makeSureFileIsParsed($smartFileInfo);
[$newStmts, $oldStmts, $oldTokens] = $this->tokensByFilePath[$smartFileInfo->getRealPath()];
return $this->formatPerservingPrinter->printToString($newStmts, $oldStmts, $oldTokens);
}
public function refactor(SmartFileInfo $smartFileInfo): void
{
$this->makeSureFileIsParsed($smartFileInfo);
[$newStmts, $oldStmts, $oldTokens] = $this->tokensByFilePath[$smartFileInfo->getRealPath()];
$newStmts = $this->rectorNodeTraverser->traverse($newStmts);
@ -121,6 +125,9 @@ final class FileProcessor
$oldStmts = $this->parser->parseFile($smartFileInfo->getRealPath());
$oldTokens = $this->lexer->getTokens();
// needed for \Rector\NodeTypeResolver\PHPStan\Scope\NodeScopeResolver
$this->tokensByFilePath[$smartFileInfo->getRealPath()] = [$oldStmts, $oldStmts, $oldTokens];
$newStmts = $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile(
$oldStmts,
$smartFileInfo->getRealPath()
@ -128,4 +135,18 @@ final class FileProcessor
return [$newStmts, $oldStmts, $oldTokens];
}
private function makeSureFileIsParsed(SmartFileInfo $smartFileInfo): void
{
if (isset($this->tokensByFilePath[$smartFileInfo->getRealPath()])) {
return;
}
throw new ShouldNotHappenException(sprintf(
'File %s was not preparsed, so it cannot be printed.%sCheck "%s" method.',
$smartFileInfo->getRealPath(),
PHP_EOL,
self::class . '::parseFileInfoToLocalCache()'
));
}
}