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 b604cc6
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 16 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
4 changes: 2 additions & 2 deletions rules/Defluent/Rector/ClassMethod/NormalToFluentRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ private function fluentizeCollectedMethodCalls(ClassMethod $classMethod): void
private function matchMethodCall(MethodCall $methodCall): ?ObjectType
{
foreach ($this->callsToFluent as $callToFluent) {
if (! $this->isObjectType($methodCall->var, $callToFluent->getObjectType())) {
if (! $this->isObjectType($methodCall->var, $callToFluent->getType())) {
continue;
}

if ($this->isNames($methodCall->name, $callToFluent->getMethodNames())) {
return $callToFluent->getObjectType();
return $callToFluent->getType();
}
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function refactor(Node $node): ?Node
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);

foreach ($this->renamedAnnotations as $renamedAnnotation) {
if (! $this->isObjectType($classLike, $renamedAnnotation->getObjectType())) {
if (! $this->isObjectType($classLike, $renamedAnnotation->getType())) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private function processFromPropertyFetch(PropertyFetch $propertyFetch): ?Proper
{
$class = $propertyFetch->getAttribute(AttributeKey::CLASS_NODE);
foreach ($this->renamedProperties as $renamedProperty) {
if (! $this->isObjectType($propertyFetch->var, $renamedProperty->getObjectType())) {
if (! $this->isObjectType($propertyFetch->var, $renamedProperty->getType())) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function refactor(Node $node): ?Node
$propertyNode = $propertyFetchNode->var;

foreach ($this->propertyAssignsToMethodCalls as $propertyAssignToMethodCall) {
if (! $this->isObjectType($propertyFetchNode->var, $propertyAssignToMethodCall->getObjectType())) {
if (! $this->isObjectType($propertyFetchNode->var, $propertyAssignToMethodCall->getType())) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getNodeTypes(): array
public function refactor(Node $node): ?Node
{
foreach ($this->methodCallRenamesWithAddedArguments as $methodCallRenameWithAddedArgument) {
if (! $this->isObjectType($node->var, $methodCallRenameWithAddedArgument->getObjectType())) {
if (! $this->isObjectType($node->var, $methodCallRenameWithAddedArgument->getType())) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion rules/Transform/Rector/New_/NewToStaticCallRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function getNodeTypes(): array
public function refactor(Node $node): ?Node
{
foreach ($this->typeToStaticCalls as $typeToStaticCall) {
if (! $this->isObjectType($node->class, $typeToStaticCall->getObjectType())) {
if (! $this->isObjectType($node->class, $typeToStaticCall->getType())) {
continue;
}

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 b604cc6

Please sign in to comment.