Tiny cherry-picks from PHPStan 1.0 update (#1058)

This commit is contained in:
Tomas Votruba 2021-10-25 16:48:32 +02:00 committed by GitHub
parent c0e95a0233
commit 48cb8a256d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 17 deletions

View File

@ -27,9 +27,9 @@
"rector/rector-doctrine": "^0.11.24",
"rector/rector-laravel": "^0.11.8",
"rector/rector-nette": "^0.11.29",
"rector/rector-phpoffice": "^0.11.4",
"rector/rector-phpunit": "^0.11.11",
"rector/rector-symfony": "^0.11.26",
"rector/rector-phpoffice": "^0.11.4",
"sebastian/diff": "^4.0.4",
"ssch/typo3-rector": "^0.11.26",
"symfony/console": "^5.3.7",

View File

@ -19,7 +19,7 @@ final class FluentMethodCallSkipper
* Skip query and builder
* @see https://ocramius.github.io/blog/fluent-interfaces-are-evil/ "When does a fluent interface make sense?
*
* @var class-string[]
* @var string[]
*/
private const ALLOWED_FLUENT_TYPES = [
// symfony

View File

@ -98,10 +98,6 @@ final class TernaryToNullCoalescingRector extends AbstractRector implements MinP
}
// none or multiple isset values cannot be handled here
if (! isset($isset->vars[0])) {
return null;
}
if (count($isset->vars) > 1) {
return null;
}

View File

@ -20,6 +20,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Config\FileLocator;
use Symfony\Component\HttpKernel\Kernel;
use Symplify\Astral\Bundle\AstralBundle;
use Symplify\AutowireArrayParameter\DependencyInjection\CompilerPass\AutowireArrayParameterCompilerPass;
use Symplify\ComposerJsonManipulator\Bundle\ComposerJsonManipulatorBundle;
use Symplify\ConsoleColorDiff\Bundle\ConsoleColorDiffBundle;
@ -83,6 +84,7 @@ final class RectorKernel extends Kernel
new ComposerJsonManipulatorBundle(),
new SkipperBundle(),
new SimplePhpDocParserBundle(),
new AstralBundle(),
];
}

View File

@ -19,7 +19,6 @@ use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\Trait_;
use PhpParser\NodeFinder;
use PhpParser\Parser;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
@ -34,6 +33,7 @@ use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator;
use Rector\NodeTypeResolver\NodeTypeResolver;
use ReflectionProperty;
use Symplify\Astral\PhpParser\SmartPhpParser;
use Symplify\SmartFileSystem\SmartFileInfo;
use Symplify\SmartFileSystem\SmartFileSystem;
@ -68,7 +68,7 @@ final class AstResolver
private array $classLikesByName = [];
public function __construct(
private Parser $parser,
private SmartPhpParser $smartPhpParser,
private SmartFileSystem $smartFileSystem,
private NodeFinder $nodeFinder,
private NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator,
@ -254,17 +254,15 @@ final class AstResolver
return null;
}
$fileContent = $this->smartFileSystem->readFile($fileName);
$nodes = $this->parser->parse($fileContent);
if ($nodes === null) {
$stmts = $this->smartPhpParser->parseFile($fileName);
if ($stmts === []) {
// avoid parsing falsy-file again
$this->classLikesByName[$classReflection->getName()] = null;
return null;
}
/** @var array<Class_|Trait_|Interface_> $classLikes */
$classLikes = $this->betterNodeFinder->findInstanceOf($nodes, ClassLike::class);
$classLikes = $this->betterNodeFinder->findInstanceOf($stmts, ClassLike::class);
$reflectionClassName = $classReflection->getName();
foreach ($classLikes as $classLike) {
@ -366,16 +364,15 @@ final class AstResolver
*/
private function parseFileNameToDecoratedNodes(string $fileName): ?array
{
$fileContent = $this->smartFileSystem->readFile($fileName);
$nodes = $this->parser->parse($fileContent);
if ($nodes === null) {
$stmts = $this->smartPhpParser->parseFile($fileName);
if ($stmts === []) {
return null;
}
$smartFileInfo = new SmartFileInfo($fileName);
$file = new File($smartFileInfo, $smartFileInfo->getContents());
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($file, $nodes);
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($file, $stmts);
}
/**