mirror of
https://github.com/rectorphp/rector.git
synced 2024-09-03 14:11:42 +00:00
phpstan fixes
This commit is contained in:
parent
fa244116d7
commit
c193d4b19f
@ -83,7 +83,10 @@ final class NodeCallerTypeResolver
|
||||
if ($node->var instanceof MethodCall) {
|
||||
$parentReturnTypes = $this->resolveMethodCallReturnTypes($node->var);
|
||||
|
||||
$methodName = $node->var->name->toString();
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $node->var->name;
|
||||
|
||||
$methodName = $identifierNode->toString();
|
||||
|
||||
$returnTypes = $this->methodReflector->resolveReturnTypesForTypesAndMethod($parentReturnTypes, $methodName);
|
||||
|
||||
|
@ -46,7 +46,11 @@ final class MethodResolver extends NodeVisitorAbstract
|
||||
{
|
||||
if ($node instanceof ClassMethod) {
|
||||
$this->methodNode = $node;
|
||||
$this->methodName = $node->name->toString();
|
||||
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $node->name;
|
||||
|
||||
$this->methodName = $identifierNode->toString();
|
||||
}
|
||||
|
||||
if ($node instanceof MethodCall && $node->name instanceof Identifier) {
|
||||
|
@ -6,6 +6,7 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Exception\NotImplementedException;
|
||||
@ -64,7 +65,10 @@ final class NewTypeResolver implements PerNodeTypeResolverInterface, NodeTypeRes
|
||||
}
|
||||
|
||||
// can be anything (dynamic)
|
||||
$propertyName = $newNode->class->name->toString();
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $newNode->class->name;
|
||||
|
||||
$propertyName = $identifierNode->toString();
|
||||
|
||||
return $this->typeContext->getTypesForProperty($propertyName);
|
||||
}
|
||||
|
@ -58,7 +58,10 @@ final class PropertyFetchTypeResolver implements PerNodeTypeResolverInterface, N
|
||||
return $this->nodeTypeResolver->resolve($propertyFetchNode->name);
|
||||
}
|
||||
|
||||
$propertyName = $propertyFetchNode->name->toString();
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $propertyFetchNode->name;
|
||||
|
||||
$propertyName = $identifierNode->toString();
|
||||
|
||||
// e.g. $r->getParameters()[0]->name
|
||||
if ($propertyFetchNode->var instanceof ArrayDimFetch) {
|
||||
|
@ -4,6 +4,7 @@ namespace Rector\NodeTypeResolver\PerNodeTypeResolver;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\VarLikeIdentifier;
|
||||
use Rector\BetterReflection\Reflector\SmartClassReflector;
|
||||
use Rector\NodeTypeResolver\Contract\PerNodeTypeResolver\PerNodeTypeResolverInterface;
|
||||
use Rector\NodeTypeResolver\TypeContext;
|
||||
@ -47,7 +48,10 @@ final class PropertyTypeResolver implements PerNodeTypeResolverInterface
|
||||
*/
|
||||
public function resolve(Node $propertyNode): array
|
||||
{
|
||||
$propertyName = $propertyNode->props[0]->name->toString();
|
||||
/** @var VarLikeIdentifier $varLikeIdentifierNode */
|
||||
$varLikeIdentifierNode = $propertyNode->props[0]->name;
|
||||
|
||||
$propertyName = $varLikeIdentifierNode->toString();
|
||||
$propertyTypes = $this->typeContext->getTypesForProperty($propertyName);
|
||||
if ($propertyTypes) {
|
||||
return $propertyTypes;
|
||||
|
@ -7,6 +7,7 @@ use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
@ -90,7 +91,10 @@ final class ConstructorPropertyTypesExtractor
|
||||
return false;
|
||||
}
|
||||
|
||||
return $node->name->toString() === '__construct';
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $node->name;
|
||||
|
||||
return $identifierNode->toString() === '__construct';
|
||||
}
|
||||
|
||||
private function isAssignThisNode(Node $node): bool
|
||||
@ -120,7 +124,7 @@ final class ConstructorPropertyTypesExtractor
|
||||
): array {
|
||||
$propertiesWithTypes = [];
|
||||
|
||||
foreach ($classMethodNode->stmts as $inConstructorNode) {
|
||||
foreach ((array) $classMethodNode->stmts as $inConstructorNode) {
|
||||
if (! $this->isAssignThisNode($inConstructorNode)) {
|
||||
continue;
|
||||
}
|
||||
@ -132,7 +136,10 @@ final class ConstructorPropertyTypesExtractor
|
||||
/** @var PropertyFetch $propertyFetchNode */
|
||||
$propertyFetchNode = $assignNode->var;
|
||||
|
||||
$propertyName = $propertyFetchNode->name->toString();
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $propertyFetchNode->name;
|
||||
|
||||
$propertyName = $identifierNode->toString();
|
||||
$propertyTypes = $constructorParametersWithTypes[$propertyName] ?? null;
|
||||
|
||||
if ($propertyName && $propertyTypes) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Rector\NodeTypeResolver\Tests\NodeCallerTypeResolver;
|
||||
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use Rector\Node\Attribute;
|
||||
use Rector\NodeTypeResolver\Tests\AbstractNodeTypeResolverTest;
|
||||
|
||||
@ -18,19 +19,25 @@ final class NestedMethodCallTest extends AbstractNodeTypeResolverTest
|
||||
|
||||
$this->assertCount(3, $methodCallNodes);
|
||||
|
||||
$this->assertSame('addRule', $methodCallNodes[0]->name->toString());
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $methodCallNodes[0]->name;
|
||||
$this->assertSame('addRule', $identifierNode->toString());
|
||||
$this->assertSame(
|
||||
['Nette\Forms\Rules'],
|
||||
$methodCallNodes[0]->getAttribute(Attribute::CALLER_TYPES)
|
||||
);
|
||||
|
||||
$this->assertSame('addCondition', $methodCallNodes[1]->name->toString());
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $methodCallNodes[1]->name;
|
||||
$this->assertSame('addCondition', $identifierNode->toString());
|
||||
$this->assertContains(
|
||||
'Nette\Forms\Controls\TextInput',
|
||||
$methodCallNodes[1]->getAttribute(Attribute::CALLER_TYPES)
|
||||
);
|
||||
|
||||
$this->assertSame('addText', $methodCallNodes[2]->name->toString());
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $methodCallNodes[2]->name;
|
||||
$this->assertSame('addText', $identifierNode->toString());
|
||||
$this->assertContains(
|
||||
'Nette\Application\UI\Form',
|
||||
$methodCallNodes[2]->getAttribute(Attribute::CALLER_TYPES)
|
||||
@ -46,12 +53,17 @@ final class NestedMethodCallTest extends AbstractNodeTypeResolverTest
|
||||
);
|
||||
|
||||
$this->assertCount(2, $methodCallNodes);
|
||||
$this->assertSame('setScope', $methodCallNodes[0]->name->toString());
|
||||
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $methodCallNodes[0]->name;
|
||||
$this->assertSame('setScope', $identifierNode->toString());
|
||||
$this->doTestAttributeEquals($methodCallNodes[0], Attribute::CALLER_TYPES, [
|
||||
'Symfony\Component\DependencyInjection\Definition',
|
||||
]);
|
||||
|
||||
$this->assertSame('register', $methodCallNodes[1]->name->toString());
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $methodCallNodes[1]->name;
|
||||
$this->assertSame('register', $identifierNode->toString());
|
||||
$this->doTestAttributeEquals($methodCallNodes[1], Attribute::CALLER_TYPES, [
|
||||
'Symfony\Component\DependencyInjection\ContainerBuilder',
|
||||
'Symfony\Component\DependencyInjection\ResettableContainerInterface',
|
||||
@ -72,17 +84,23 @@ final class NestedMethodCallTest extends AbstractNodeTypeResolverTest
|
||||
|
||||
$this->assertCount(3, $methodCallNodes);
|
||||
|
||||
$this->assertSame('getParameters', $methodCallNodes[0]->name->toString());
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $methodCallNodes[0]->name;
|
||||
$this->assertSame('getParameters', $identifierNode->toString());
|
||||
$this->doTestAttributeEquals($methodCallNodes[0], Attribute::CALLER_TYPES, [
|
||||
'Nette\DI\Container',
|
||||
]);
|
||||
|
||||
$this->assertSame('addService', $methodCallNodes[1]->name->toString());
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $methodCallNodes[1]->name;
|
||||
$this->assertSame('addService', $identifierNode->toString());
|
||||
$this->doTestAttributeEquals($methodCallNodes[1], Attribute::CALLER_TYPES, [
|
||||
'Nette\DI\Container',
|
||||
]);
|
||||
|
||||
$this->assertSame('createContainer', $methodCallNodes[2]->name->toString());
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $methodCallNodes[2]->name;
|
||||
$this->assertSame('createContainer', $identifierNode->toString());
|
||||
$this->doTestAttributeEquals($methodCallNodes[2], Attribute::CALLER_TYPES, [
|
||||
'Nette\Config\Configurator',
|
||||
'Nette\Object',
|
||||
|
@ -4,6 +4,7 @@ namespace Rector\NodeValueResolver\PerNodeValueResolver;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Identifier;
|
||||
use Rector\Node\Attribute;
|
||||
use Rector\NodeValueResolver\Contract\PerNodeValueResolver\PerNodeValueResolverInterface;
|
||||
|
||||
@ -22,7 +23,10 @@ final class ClassConstFetchResolver implements PerNodeValueResolverInterface
|
||||
$class = $classConstFetchNode->class->getAttribute(Attribute::RESOLVED_NAME)
|
||||
->toString();
|
||||
|
||||
$constant = $classConstFetchNode->name->toString();
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $classConstFetchNode->name;
|
||||
|
||||
$constant = $identifierNode->toString();
|
||||
|
||||
return $class . '::' . $constant;
|
||||
}
|
||||
|
11
phpstan.neon
11
phpstan.neon
@ -1,5 +1,8 @@
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
# stricter return type of parent
|
||||
- '#PHPDoc tag @return with type mixed is not subtype of native type (int|string)#'
|
||||
|
||||
# property overriden
|
||||
- '#Rector\\NodeTraverser\\(Cloning|Shutdown)NodeTraverser::__construct\(\) does not call parent constructor from PhpParser\\NodeTraverser#'
|
||||
|
||||
@ -14,6 +17,7 @@ parameters:
|
||||
# subtype
|
||||
- '#Property PhpParser\\Node\\Param::\$type \(PhpParser\\Node\\Name|PhpParser\\Node\\NullableType\|string\|null\) does not accept PhpParser\\Node\\Identifier|PhpParser\\Node\\Name\|PhpParser\\Node\\NullableType#'
|
||||
|
||||
|
||||
# known values
|
||||
- '#Method Rector\\Node\\NodeFactory::create(Null|False|True)Constant\(\) should return PhpParser\\Node\\Expr\\ConstFetch but returns PhpParser\\Node\\Expr#'
|
||||
- '#Method Rector\\Node\\NodeFactory::createNamespace\(\) should return PhpParser\\Node\\Stmt\\Namespace_ but returns PhpParser\\Node#'
|
||||
@ -29,6 +33,11 @@ parameters:
|
||||
- '#PHPDoc tag @param for parameter \$classLikeNode with type PhpParser\\Builder\\Trait_\|PhpParser\\Node\\Stmt\\Class_\|PhpParser\\Node\\Stmt#'
|
||||
- '#Instanceof between string\|null and PhpParser\\Node\\Identifier will always evaluate to false#'
|
||||
- '#Method Rector\\NodeTraverserQueue\\BetterNodeFinder::findFirstAncestorInstanceOf\(\) should return PhpParser\\Node\|null but returns object#'
|
||||
- '#Access to an undefined property PhpParser\\Node\\Stmt\\(Class_|ClassLike)::\$namespacedName#'
|
||||
- '#Property Rector\\NodeTypeResolver\\NodeVisitor\\NamespaceResolver::\$useNodes \(array<PhpParser\\Node\\Stmt\\Use_>\) does not accept array<PhpParser\\Node>#'
|
||||
- '#Parameter \#1 \$classMethodNode of method Rector\\NodeTypeResolver\\TypesExtractor\\ConstructorPropertyTypesExtractor::extractPropertiesFromConstructorMethodNode\(\) expects PhpParser\\Node\\Stmt\\ClassMethod, PhpParser\\Node given#'
|
||||
- '#Instanceof between PhpParser\\Node\\Expr\|string and PhpParser\\Node\\Name will always evaluate to false#'
|
||||
- '#Method Rector\\BetterReflection\\Reflector\\SmartClassReflector::reflect\(\) should return Rector\\BetterReflection\\Reflection\\ReflectionClass\|null but returns Rector\\BetterReflection\\Reflection\\Reflection#'
|
||||
|
||||
# buggy
|
||||
- '#Parameter \#1 \$classLikeNode of method Rector\\NodeAnalyzer\\ClassLikeAnalyzer::resolveExtendsTypes\(\) expects PhpParser\\Node\\Stmt\\Class_\|PhpParser\\Node\\Stmt\\Interface_, PhpParser\\Node\\Stmt\\ClassLike given#'
|
||||
@ -37,6 +46,8 @@ parameters:
|
||||
- '#Access to an undefined property PhpParser\\Node\\Param::\$var#'
|
||||
- '#Access to an undefined property PhpParser\\Node\\Arg|PhpParser\\Node\\Expr\|PhpParser\\Node\\Param::\$value#'
|
||||
- '#Call to an undefined method PhpParser\\BuilderFactory::args\(\)#'
|
||||
- "#Casting to string something that's already string#"
|
||||
- '#Call to an undefined method PhpParser\\Node\\Stmt\\UseUse::getAlias\(\)#'
|
||||
|
||||
excludes_analyse:
|
||||
# test files
|
||||
|
Loading…
Reference in New Issue
Block a user