fix multiple trait analysis

This commit is contained in:
Tomas Votruba 2019-08-06 08:32:12 +02:00
parent 5c1de848e7
commit 11732c84e7
5 changed files with 27 additions and 10 deletions

View File

@ -3857,7 +3857,7 @@ services:
- class: `Rector\Php\Rector\FuncCall\PregReplaceEModifierRector`
The /e modifier is no longer supported, use preg_replace_callback instead
The /e modifier is no longer supported, use preg_replace_callback instead
```diff
class SomeClass

View File

@ -917,7 +917,7 @@ if (true) {
```php
?>
<strong>feel</strong><?php
<strong>feel</strong><?php
```
<br>

View File

@ -69,7 +69,6 @@ final class NodeScopeResolver
{
$this->removeDeepChainMethodCallNodes($nodes);
$this->phpStanNodeScopeResolver->setAnalysedFiles([$filePath]);
$scope = $this->scopeFactory->createFromFile($filePath);
// skip chain method calls, performance issue: https://github.com/phpstan/phpstan/issues/254

View File

@ -3,6 +3,7 @@
namespace Rector\Application;
use PHPStan\AnalysedCodeException;
use PHPStan\Analyser\NodeScopeResolver;
use Rector\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Application\FileSystem\RemovedAndAddedFilesProcessor;
use Rector\Configuration\Configuration;
@ -68,6 +69,11 @@ final class RectorApplication
*/
private $enabledRectorsProvider;
/**
* @var NodeScopeResolver
*/
private $nodeScopeResolver;
public function __construct(
SymfonyStyle $symfonyStyle,
FileSystemFileProcessor $fileSystemFileProcessor,
@ -76,7 +82,8 @@ final class RectorApplication
FileProcessor $fileProcessor,
EnabledRectorsProvider $enabledRectorsProvider,
RemovedAndAddedFilesCollector $removedAndAddedFilesCollector,
RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor
RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor,
NodeScopeResolver $nodeScopeResolver
) {
$this->symfonyStyle = $symfonyStyle;
$this->fileSystemFileProcessor = $fileSystemFileProcessor;
@ -86,6 +93,7 @@ final class RectorApplication
$this->removedAndAddedFilesCollector = $removedAndAddedFilesCollector;
$this->removedAndAddedFilesProcessor = $removedAndAddedFilesProcessor;
$this->enabledRectorsProvider = $enabledRectorsProvider;
$this->nodeScopeResolver = $nodeScopeResolver;
}
/**
@ -103,6 +111,9 @@ final class RectorApplication
$this->symfonyStyle->progressStart($fileCount * 3);
}
// PHPStan has to know about all files!
$this->configurePHPStanNodeScopeResolver($fileInfos);
// 1. parse files to nodes
foreach ($fileInfos as $fileInfo) {
$this->tryCatchWrapper($fileInfo, function (SmartFileInfo $smartFileInfo): void {
@ -192,4 +203,17 @@ final class RectorApplication
$this->symfonyStyle->progressAdvance();
}
}
/**
* @param SmartFileInfo[] $fileInfos
*/
private function configurePHPStanNodeScopeResolver(array $fileInfos): void
{
$filePaths = [];
foreach ($fileInfos as $fileInfo) {
$filePaths[] = $fileInfo->getRealPath();
}
$this->nodeScopeResolver->setAnalysedFiles($filePaths);
}
}

View File

@ -575,12 +575,6 @@ final class ParsedNodesByType
*/
private function addCall(Node $node): void
{
if ($node->name->name === 'getStatus') {
//dump($node);
dump($classTypes = $this->resolveNodeClassTypes($node));
die;
}
// one node can be of multiple-class types
$classTypes = $this->resolveNodeClassTypes($node);
if ($classTypes === []) { // anonymous