mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-05 10:50:48 +00:00
fix NotImplementedException by dropping useless __CLASS__
This commit is contained in:
parent
27ed12e52b
commit
822cfaf514
|
@ -59,8 +59,7 @@ final class RectorFactory
|
|||
}
|
||||
|
||||
throw new NotImplementedException(sprintf(
|
||||
'%s::%s() was unable to create a Rector based on "%s" Deprecation. Create a new method there.',
|
||||
self::class,
|
||||
'%s() was unable to create a Rector based on "%s" Deprecation. Create a new method there.',
|
||||
__METHOD__,
|
||||
get_class($deprecation)
|
||||
));
|
||||
|
|
|
@ -82,8 +82,7 @@ final class ArgumentToDeprecationTransformer
|
|||
}
|
||||
|
||||
throw new NotImplementedException(sprintf(
|
||||
'Not implemented yet. Go to "%s::%s()" and add check for "%s" node.',
|
||||
__CLASS__,
|
||||
'Not implemented yet. Go to "%s()" and add check for "%s" node.',
|
||||
__METHOD__,
|
||||
get_class($node)
|
||||
));
|
||||
|
@ -146,8 +145,7 @@ final class ArgumentToDeprecationTransformer
|
|||
}
|
||||
|
||||
throw new NotImplementedException(sprintf(
|
||||
'%s::%s() did not resolve %s messsage, so %s was not created. Implement it.',
|
||||
self::class,
|
||||
'%s() did not resolve %s messsage, so %s was not created. Implement it.',
|
||||
__METHOD__,
|
||||
$message,
|
||||
DeprecationInterface::class
|
||||
|
|
|
@ -3,15 +3,20 @@
|
|||
namespace Rector\NodeTypeResolver\NodeVisitor;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
use PhpParser\PrettyPrinter\Standard;
|
||||
use Rector\Exception\NotImplementedException;
|
||||
use Rector\Node\Attribute;
|
||||
use Rector\NodeTypeResolver\TypeContext;
|
||||
|
||||
|
@ -30,7 +35,12 @@ final class TypeResolver extends NodeVisitorAbstract
|
|||
*/
|
||||
private $perNodeResolvers = [];
|
||||
|
||||
public function __construct(TypeContext $typeContext)
|
||||
/**
|
||||
* @var Standard
|
||||
*/
|
||||
private $standardPrinter;
|
||||
|
||||
public function __construct(TypeContext $typeContext, Standard $standardPrinter)
|
||||
{
|
||||
$this->typeContext = $typeContext;
|
||||
|
||||
|
@ -41,12 +51,16 @@ final class TypeResolver extends NodeVisitorAbstract
|
|||
$this->perNodeResolvers[Assign::class] = function (Assign $assignNode): void {
|
||||
$this->processAssignNode($assignNode);
|
||||
};
|
||||
|
||||
// add subtypes for PropertyFetch
|
||||
$this->perNodeResolvers[PropertyFetch::class] = function (PropertyFetch $propertyFetchNode): void {
|
||||
$this->processPropertyFetch($propertyFetchNode);
|
||||
};
|
||||
|
||||
$this->perNodeResolvers[Property::class] = function (Property $propertyNode): void {
|
||||
$this->processProperty($propertyNode);
|
||||
};
|
||||
$this->standardPrinter = $standardPrinter;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,10 +94,24 @@ final class TypeResolver extends NodeVisitorAbstract
|
|||
|
||||
private function getTypeFromNewNode(New_ $newNode): string
|
||||
{
|
||||
/** @var FullyQualified $fqnName */
|
||||
$fqnName = $newNode->class->getAttribute(Attribute::RESOLVED_NAME);
|
||||
if ($newNode->class instanceof Variable) {
|
||||
$variableName = $newNode->class->name;
|
||||
dump($variableName);
|
||||
dump($this->typeContext->getTypeForVariable($variableName));
|
||||
|
||||
return $fqnName->toString();
|
||||
} elseif ($newNode->class instanceof Name) {
|
||||
/** @var FullyQualified $fqnName */
|
||||
$fqnName = $newNode->class->getAttribute(Attribute::RESOLVED_NAME);
|
||||
|
||||
return $fqnName->toString();
|
||||
}
|
||||
|
||||
throw new NotImplementedException(sprintf(
|
||||
'Not implemented yet. Go to "%s()" and add check for "%s" node.',
|
||||
|
||||
__METHOD__,
|
||||
get_class($newNode->class)
|
||||
));
|
||||
}
|
||||
|
||||
private function processVariableNode(Variable $variableNode): void
|
||||
|
@ -121,11 +149,36 @@ final class TypeResolver extends NodeVisitorAbstract
|
|||
|
||||
private function processPropertyFetch(PropertyFetch $propertyFetchNode): void
|
||||
{
|
||||
if ($propertyFetchNode->var instanceof New_) {
|
||||
$propertyType = $propertyFetchNode->var->class->toString();
|
||||
$propertyFetchNode->setAttribute(Attribute::TYPE, $propertyType);
|
||||
return;
|
||||
}
|
||||
|
||||
// e.g. $r->getParameters()[0]->name
|
||||
if ($propertyFetchNode->var instanceof ArrayDimFetch) {
|
||||
if ($propertyFetchNode->var->var instanceof MethodCall) {
|
||||
/** @var Variable $variableNode */
|
||||
$variableNode = $propertyFetchNode->var->var->var;
|
||||
$variableName = $variableNode->name;
|
||||
$variableType = $this->typeContext->getTypeForVariable($variableName);
|
||||
|
||||
$variableNode->setAttribute(Attribute::TYPE, $variableType);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($propertyFetchNode->var->name !== 'this') {
|
||||
return;
|
||||
}
|
||||
|
||||
$propertyName = (string) $propertyFetchNode->name;
|
||||
if ($propertyFetchNode->name instanceof Variable) {
|
||||
$propertyName = $propertyFetchNode->name->name;
|
||||
} else {
|
||||
$propertyName = (string) $propertyFetchNode->name;
|
||||
}
|
||||
|
||||
$propertyType = $this->typeContext->getTypeForProperty($propertyName);
|
||||
|
||||
if ($propertyType) {
|
||||
|
|
|
@ -51,8 +51,7 @@ final class DocBlockAnalyzer
|
|||
}
|
||||
|
||||
throw new NotImplementedException(sprintf(
|
||||
'Not implemented yet. Go to "%s::%s()" and add check for "%s" annotation.',
|
||||
__CLASS__,
|
||||
'Not implemented yet. Go to "%s()" and add check for "%s" annotation.',
|
||||
__METHOD__,
|
||||
$annotation
|
||||
));
|
||||
|
|
|
@ -107,8 +107,7 @@ final class NodeFactory
|
|||
$arrayItems[] = new ArrayItem($string);
|
||||
} else {
|
||||
throw new NotImplementedException(sprintf(
|
||||
'Not implemented yet. Go to "%s::%s()" and add check for "%s" node.',
|
||||
__CLASS__,
|
||||
'Not implemented yet. Go to "%s()" and add check for "%s" node.',
|
||||
__METHOD__,
|
||||
get_class($item)
|
||||
));
|
||||
|
|
Loading…
Reference in New Issue
Block a user