[DeprecationExtractor] improve fail exception

This commit is contained in:
TomasVotruba 2017-11-09 15:19:35 +01:00
parent 27adddade6
commit 5b84664fa4
3 changed files with 25 additions and 9 deletions

View File

@ -4,10 +4,12 @@ namespace Rector\DeprecationExtractor;
use PhpParser\NodeTraverser;
use Rector\Contract\Parser\ParserInterface;
use Rector\DeprecationExtractor\Exception\DeprecationExtractorException;
use Rector\DeprecationExtractor\NodeVisitor\DeprecationDetector;
use Rector\FileSystem\PhpFilesFinder;
use Rector\NodeTraverser\NodeTraverserFactory;
use Rector\NodeTraverser\StandaloneTraverseNodeTraverser;
use Throwable;
final class DeprecationExtractor
{
@ -52,11 +54,20 @@ final class DeprecationExtractor
$files = $this->phpFilesFinder->findInDirectoriesAndFiles($source);
foreach ($files as $file) {
$nodes = $this->parser->parseFile($file->getRealPath());
// this completes parent & child nodes, types and classses
$this->standaloneTraverseNodeTraverser->traverse($nodes);
try {
$nodes = $this->parser->parseFile($file->getRealPath());
// this completes parent & child nodes, types and classses
$this->standaloneTraverseNodeTraverser->traverse($nodes);
$this->deprecationDetectorNodeTraverser->traverse($nodes);
$this->deprecationDetectorNodeTraverser->traverse($nodes);
} catch (Throwable $throwable) {
$message = sprintf(
'Extracting deperactions from "%s" file failed.',
$file->getRealPath()
);
throw new DeprecationExtractorException($message, 0, $throwable);
}
}
}
}

View File

@ -0,0 +1,9 @@
<?php declare(strict_types=1);
namespace Rector\DeprecationExtractor\Exception;
use Exception;
final class DeprecationExtractorException extends Exception
{
}

View File

@ -50,11 +50,7 @@ final class PropertyFetchTypeResolver implements PerNodeTypeResolverInterface, N
*/
public function resolve(Node $propertyFetchNode): array
{
if ($propertyFetchNode->name instanceof Variable) {
return $this->nodeTypeResolver->resolve($propertyFetchNode->name);
}
if ($propertyFetchNode->name instanceof ArrayDimFetch) {
if ($propertyFetchNode->name instanceof Variable || $propertyFetchNode->name instanceof ArrayDimFetch) {
return $this->nodeTypeResolver->resolve($propertyFetchNode->name);
}