mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-25 20:23:49 +01:00
apply RectorApplication try-catch on each single step
This commit is contained in:
parent
9cb3484b36
commit
86849b722a
@ -82,7 +82,9 @@ final class RectorApplication
|
||||
// 1. parse files to nodes
|
||||
foreach ($fileInfos as $fileInfo) {
|
||||
$this->advance();
|
||||
$this->fileProcessor->parseFileInfoToLocalCache($fileInfo);
|
||||
$this->tryCatchWrapper($fileInfo, function (SmartFileInfo $smartFileInfo): void {
|
||||
$this->fileProcessor->parseFileInfoToLocalCache($smartFileInfo);
|
||||
});
|
||||
}
|
||||
|
||||
// 2. change nodes with Rectors
|
||||
@ -93,12 +95,14 @@ final class RectorApplication
|
||||
|
||||
// 3. print to file or string
|
||||
foreach ($fileInfos as $fileInfo) {
|
||||
$this->processFileInfo($fileInfo);
|
||||
if ($this->symfonyStyle->isVerbose()) {
|
||||
$this->symfonyStyle->writeln($fileInfo->getRealPath());
|
||||
} else {
|
||||
$this->symfonyStyle->progressAdvance();
|
||||
}
|
||||
$this->tryCatchWrapper($fileInfo, function (SmartFileInfo $smartFileInfo): void {
|
||||
$this->processFileInfo($smartFileInfo);
|
||||
if ($this->symfonyStyle->isVerbose()) {
|
||||
$this->symfonyStyle->writeln($smartFileInfo->getRealPath());
|
||||
} else {
|
||||
$this->symfonyStyle->progressAdvance();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$this->symfonyStyle->newLine(2);
|
||||
@ -112,21 +116,28 @@ final class RectorApplication
|
||||
}
|
||||
|
||||
private function refactorFileInfo(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->tryCatchWrapper($fileInfo, function (SmartFileInfo $smartFileInfo): void {
|
||||
$this->fileProcessor->refactor($smartFileInfo);
|
||||
});
|
||||
}
|
||||
|
||||
private function tryCatchWrapper(SmartFileInfo $smartFileInfo, callable $callback): void
|
||||
{
|
||||
try {
|
||||
$this->fileProcessor->refactor($fileInfo);
|
||||
$callback($smartFileInfo);
|
||||
} catch (AnalysedCodeException $analysedCodeException) {
|
||||
if ($this->configuration->shouldHideAutoloadErrors()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->errorAndDiffCollector->addAutoloadError($analysedCodeException, $fileInfo);
|
||||
$this->errorAndDiffCollector->addAutoloadError($analysedCodeException, $smartFileInfo);
|
||||
} catch (Throwable $throwable) {
|
||||
if ($this->symfonyStyle->isVerbose()) {
|
||||
throw $throwable;
|
||||
}
|
||||
|
||||
$this->errorAndDiffCollector->addThrowableWithFileInfo($throwable, $fileInfo);
|
||||
$this->errorAndDiffCollector->addThrowableWithFileInfo($throwable, $smartFileInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user