Skip to content

Commit

Permalink
use getType() over getObjectType()
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Oct 7, 2021
1 parent be3d0c6 commit a0fbe15
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function refactor(Node $node): ?Node
$type = $phpDocInfo->getVarType();

if (! $type instanceof UnionType) {
$type = $this->getObjectType($assign->expr);
$type = $this->getType($assign->expr);
}

if (! $type instanceof UnionType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function refactor(Node $node): ?Node
continue;
}

$propertyFetchVarType = $this->getObjectType($issetVar->var);
$propertyFetchVarType = $this->getType($issetVar->var);

if ($propertyFetchVarType instanceof TypeWithClassName) {
if (! $this->reflectionProvider->hasClass($propertyFetchVarType->getClassName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function refactor(Node $node): ?Node

private function refactorPropertyFetch(PropertyFetch $propertyFetch): MethodCall|null
{
$callerType = $this->getObjectType($propertyFetch->var);
$callerType = $this->getType($propertyFetch->var);
if (! $callerType instanceof TypeWithClassName) {
return null;
}
Expand Down Expand Up @@ -143,7 +143,7 @@ private function refactorPropertyFetch(PropertyFetch $propertyFetch): MethodCall

private function refactorMagicSet(Expr $expr, PropertyFetch $propertyFetch): MethodCall|null
{
$propertyCallerType = $this->getObjectType($propertyFetch->var);
$propertyCallerType = $this->getType($propertyFetch->var);
if (! $propertyCallerType instanceof ObjectType) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function processClassMethod(Class_ $class, ClassMethod $classMethod): vo
continue;
}

$paramType = $this->getObjectType($paramNode);
$paramType = $this->getType($paramNode);

/** @var string $paramName */
$paramName = $this->getName($paramNode->var);
Expand All @@ -124,7 +124,7 @@ private function isActionInjectedParamNode(Param $param): bool
return false;
}

$paramStaticType = $this->getObjectType($param);
$paramStaticType = $this->getType($param);
if (! $paramStaticType instanceof ObjectType) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function refactor(Node $node): ?Node
private function resolveStaticCallClassName(StaticCall $staticCall): ?string
{
if ($staticCall->class instanceof PropertyFetch) {
$objectType = $this->getObjectType($staticCall->class);
$objectType = $this->getType($staticCall->class);
if ($objectType instanceof ObjectType) {
return $objectType->getClassName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function provideMinPhpVersion(): int
private function processNullableType(Property $property, Param $param): void
{
if ($this->nodeTypeResolver->isNullableType($property)) {
$objectType = $this->getObjectType($property);
$objectType = $this->getType($property);
$param->type = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($objectType, TypeKind::PARAM());
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,28 @@ protected function isObjectType(Node $node, ObjectType $objectType): bool
return $this->nodeTypeResolver->isObjectType($node, $objectType);
}

/**
* @deprecated
* Use @see AbstractRector::getType() instead, as single method to get types
*/
protected function getStaticType(Node $node): Type
{
return $this->nodeTypeResolver->getStaticType($node);
}

/**
* @deprecated
* Use getStaticType() instead, as single method to get types
* Use @see AbstractRector::getType() instead, as single method to get types
*/
protected function getObjectType(Node $node): Type
{
return $this->getType($node);
}

/**
* Use this method for getting expr|node type
*/
protected function getType(Node $node): Type
{
return $this->nodeTypeResolver->resolve($node);
}
Expand Down

0 comments on commit a0fbe15

Please sign in to comment.