Updated Rector to commit 47fa234379b7b9f28081e8bc6e683628f8d53f2b

47fa234379 [CodeQuality] Add Variable support on class arg on InlineIsAInstanceOfRector (#3261)
This commit is contained in:
Tomas Votruba 2023-01-02 11:58:30 +00:00
parent b8f374dc0e
commit 0fc42c2559
17 changed files with 34 additions and 27 deletions

View File

@ -269,7 +269,7 @@ final class PhpDocInfo
{
$phpDocNodeTraverser = new PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable($this->phpDocNode, '', function (Node $node) use($typeToRemove) : ?int {
if ($node instanceof PhpDocTagNode && \is_a($node->value, $typeToRemove, \true)) {
if ($node instanceof PhpDocTagNode && $node->value instanceof $typeToRemove) {
// keep special annotation for tools
if (\strncmp($node->name, '@psalm-', \strlen('@psalm-')) === 0) {
return null;
@ -280,7 +280,7 @@ final class PhpDocInfo
$this->markAsChanged();
return PhpDocNodeTraverser::NODE_REMOVE;
}
if (!\is_a($node, $typeToRemove, \true)) {
if (!$node instanceof $typeToRemove) {
return null;
}
$this->markAsChanged();
@ -401,7 +401,7 @@ final class PhpDocInfo
{
foreach (self::TAGS_TYPES_TO_NAMES as $tagValueNodeType => $name) {
/** @var class-string<PhpDocTagNode> $tagValueNodeType */
if (\is_a($phpDocTagValueNode, $tagValueNodeType, \true)) {
if ($phpDocTagValueNode instanceof $tagValueNodeType) {
return $name;
}
}

View File

@ -21,7 +21,7 @@ final class PhpDocNodeByTypeFinder
$phpDocNodeTraverser = new PhpDocNodeTraverser();
$foundNodes = [];
$phpDocNodeTraverser->traverseWithCallable($phpDocNode, '', static function (Node $node) use(&$foundNodes, $desiredType) : Node {
if (!\is_a($node, $desiredType, \true)) {
if (!$node instanceof $desiredType) {
return $node;
}
/** @var TNode $node */

View File

@ -37,7 +37,7 @@ final class ScopeAwareNodeFinder
return \true;
}
foreach ($parentNestingBreakTypes as $parentNestingBreakType) {
if (!\is_a($node, $parentNestingBreakType, \true)) {
if (!$node instanceof $parentNestingBreakType) {
continue;
}
$this->isBreakingNodeFoundFirst = \true;

View File

@ -257,7 +257,7 @@ final class NodeTypeResolver
return \false;
}
$bareType = TypeCombinator::removeNull($nodeType);
return \is_a($bareType, $desiredType, \true);
return $bareType instanceof $desiredType;
}
public function getFullyQualifiedClassName(TypeWithClassName $typeWithClassName) : string
{
@ -308,7 +308,7 @@ final class NodeTypeResolver
private function resolveByNodeTypeResolvers(Node $node) : ?Type
{
foreach ($this->nodeTypeResolvers as $nodeClass => $nodeTypeResolver) {
if (!\is_a($node, $nodeClass, \true)) {
if (!$node instanceof $nodeClass) {
continue;
}
return $nodeTypeResolver->resolve($node);

View File

@ -43,7 +43,7 @@ final class CastTypeResolver implements NodeTypeResolverInterface
public function resolve(Node $node) : Type
{
foreach (self::CAST_CLASS_TO_TYPE_MAP as $castClass => $typeClass) {
if (\is_a($node, $castClass, \true)) {
if ($node instanceof $castClass) {
return new $typeClass();
}
}

View File

@ -81,7 +81,7 @@ final class NodeValueResolver
}
// these values cannot be resolved in reliable way
foreach (self::UNRESOLVABLE_TYPES as $unresolvableType) {
if (\is_a($expr, $unresolvableType, \true)) {
if ($expr instanceof $unresolvableType) {
throw new ConstExprEvaluationException('The node "%s" value is not possible to resolve. Provide different one.');
}
}

View File

@ -8,6 +8,7 @@ use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name\FullyQualified;
use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\ObjectType;
@ -66,6 +67,12 @@ CODE_SAMPLE
if (!$this->isFirstObjectType($firstArgValue)) {
return null;
}
/**
* instanceof with Variable is ok, while on FuncCal with instanceof cause fatal error, see https://3v4l.org/IHb30
*/
if ($args[1]->value instanceof Variable) {
return new Instanceof_($firstArgValue, $args[1]->value);
}
$className = $this->resolveClassName($args[1]->value);
if ($className === null) {
return null;

View File

@ -109,7 +109,7 @@ CODE_SAMPLE
return null;
}
$sameNodeType = self::CAST_CLASS_TO_NODE_TYPE[$nodeClass];
if (!\is_a($nodeType, $sameNodeType, \true)) {
if (!$nodeType instanceof $sameNodeType) {
return null;
}
if ($this->shouldSkip($node->expr)) {

View File

@ -57,7 +57,7 @@ final class SideEffectNodeDetector
return \false;
}
foreach (self::SIDE_EFFECT_NODE_TYPES as $sideEffectNodeType) {
if (\is_a($expr, $sideEffectNodeType, \true)) {
if ($expr instanceof $sideEffectNodeType) {
return \false;
}
}

View File

@ -30,7 +30,7 @@ final class AlwaysStrictBoolExprAnalyzer
public function isStrictBoolExpr(Expr $expr) : bool
{
foreach (self::BOOL_TYPE_NODES as $boolTypeNode) {
if (\is_a($expr, $boolTypeNode, \true)) {
if ($expr instanceof $boolTypeNode) {
return \true;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'cba980b719f48eb580f8afcf4e3843843436ba35';
public const PACKAGE_VERSION = '47fa234379b7b9f28081e8bc6e683628f8d53f2b';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-01-02 12:48:53';
public const RELEASE_DATE = '2023-01-02 12:54:27';
/**
* @var int
*/

View File

@ -54,7 +54,7 @@ final class CallAnalyzer
return $isObjectCallLeft || $isObjectCallRight;
}
foreach (self::OBJECT_CALL_TYPES as $objectCallType) {
if (\is_a($expr, $objectCallType, \true)) {
if ($expr instanceof $objectCallType) {
return \true;
}
}

View File

@ -118,7 +118,7 @@ final class BinaryOpManipulator
return $condition;
}
return static function (Node $node) use($condition) : bool {
return \is_a($node, $condition, \true);
return $node instanceof $condition;
};
}
/**

View File

@ -249,6 +249,6 @@ final class IfManipulator
if (\count($stmts) !== 1) {
return \false;
}
return \is_a($stmts[0], $desiredType);
return $stmts[0] instanceof $desiredType;
}
}

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit698705ff76bcaee632e92c2b89a6b858::getLoader();
return ComposerAutoloaderInit72bf78bd619f9883efa43bdc150df9dd::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit698705ff76bcaee632e92c2b89a6b858
class ComposerAutoloaderInit72bf78bd619f9883efa43bdc150df9dd
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit698705ff76bcaee632e92c2b89a6b858
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit698705ff76bcaee632e92c2b89a6b858', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit72bf78bd619f9883efa43bdc150df9dd', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit698705ff76bcaee632e92c2b89a6b858', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit72bf78bd619f9883efa43bdc150df9dd', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit698705ff76bcaee632e92c2b89a6b858::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit72bf78bd619f9883efa43bdc150df9dd::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit698705ff76bcaee632e92c2b89a6b858::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit72bf78bd619f9883efa43bdc150df9dd::$files;
$requireFile = static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit698705ff76bcaee632e92c2b89a6b858
class ComposerStaticInit72bf78bd619f9883efa43bdc150df9dd
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3062,9 +3062,9 @@ class ComposerStaticInit698705ff76bcaee632e92c2b89a6b858
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit698705ff76bcaee632e92c2b89a6b858::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit698705ff76bcaee632e92c2b89a6b858::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit698705ff76bcaee632e92c2b89a6b858::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit72bf78bd619f9883efa43bdc150df9dd::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit72bf78bd619f9883efa43bdc150df9dd::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit72bf78bd619f9883efa43bdc150df9dd::$classMap;
}, null, ClassLoader::class);
}