Skip to content

Commit

Permalink
skip privatization, as unknown side effect (#2542)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 20, 2022
1 parent d4ec140 commit a16bc1b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class DefaultOfArray
});
}

private function sortMe($values = [])
public function sortMe($values = [])
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class HasDefaultValue2 extends AbstractExtension
];
}

private function run($a, $b = "test")
public function run($a, $b = "test")
{
return $a . $b;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@

use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\Php\PhpMethodReflection;
use PHPStan\Type\ThisType;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\NodeCollector\NodeAnalyzer\ArrayCallableMethodMatcher;
use Rector\NodeCollector\ValueObject\ArrayCallable;
use Rector\Php72\NodeFactory\AnonymousFunctionFactory;
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -33,7 +29,6 @@ public function __construct(
private readonly AnonymousFunctionFactory $anonymousFunctionFactory,
private readonly ReflectionResolver $reflectionResolver,
private readonly ArrayCallableMethodMatcher $arrayCallableMethodMatcher,
private readonly VisibilityManipulator $visibilityManipulator,
) {
}

Expand Down Expand Up @@ -103,8 +98,6 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
return null;
}

$this->privatizeLocalClassMethod($arrayCallable, $node);

$phpMethodReflection = $this->reflectionResolver->resolveMethodReflection(
$arrayCallable->getClass(),
$arrayCallable->getMethod(),
Expand All @@ -120,27 +113,4 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
$arrayCallable->getCallerExpr()
);
}

private function privatizeLocalClassMethod(ArrayCallable $arrayCallable, Array_ $array): void
{
$callerExpr = $arrayCallable->getCallerExpr();
$callerType = $this->getType($callerExpr);

// local method, lets make it private
if (! $callerType instanceof ThisType) {
return;
}

$methodName = $arrayCallable->getMethod();

$class = $this->betterNodeFinder->findParentType($array, Class_::class);
if (! $class instanceof Class_) {
return;
}

$currentClassMethod = $class->getMethod($methodName);
if ($currentClassMethod instanceof ClassMethod) {
$this->visibilityManipulator->makePrivate($currentClassMethod);
}
}
}

0 comments on commit a16bc1b

Please sign in to comment.