Skip to content

Commit

Permalink
Updated Rector to commit 2a394c7
Browse files Browse the repository at this point in the history
rectorphp/rector-src@2a394c7 Reflection cleanup + inline union types for couple of param docs (#330)
  • Loading branch information
TomasVotruba committed Jun 29, 2021
1 parent 5080937 commit a7f25f1
Show file tree
Hide file tree
Showing 37 changed files with 150 additions and 159 deletions.
4 changes: 2 additions & 2 deletions packages/NodeNestingScope/ParentScopeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public function __construct(\Rector\Core\PhpParser\Node\BetterNodeFinder $better
$this->betterNodeFinder = $betterNodeFinder;
}
/**
* @return ClassMethod|Function_|Class_|Namespace_|Closure|null
* @return \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Namespace_|\PhpParser\Node\Expr\Closure|null
*/
public function find(\PhpParser\Node $node) : ?\PhpParser\Node
public function find(\PhpParser\Node $node)
{
return $this->betterNodeFinder->findParentTypes($node, [\PhpParser\Node\Expr\Closure::class, \PhpParser\Node\Stmt\Function_::class, \PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Stmt\Class_::class, \PhpParser\Node\Stmt\Namespace_::class]);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/NodeRemoval/NodeRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ public function removeNodes(array $nodes) : void
}
}
/**
* @param Closure|ClassMethod|Function_ $node
* @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
*/
public function removeStmt(\PhpParser\Node $node, int $key) : void
public function removeStmt($functionLike, int $key) : void
{
if ($node->stmts === null) {
if ($functionLike->stmts === null) {
throw new \Rector\Core\Exception\ShouldNotHappenException();
}
// notify about remove node
$this->rectorChangeCollector->notifyNodeFileInfo($node->stmts[$key]);
unset($node->stmts[$key]);
$this->rectorChangeCollector->notifyNodeFileInfo($functionLike->stmts[$key]);
unset($functionLike->stmts[$key]);
}
/**
* @param int|\PhpParser\Node\Param $keyOrParam
Expand Down
4 changes: 2 additions & 2 deletions rules/Arguments/ArgumentDefaultValueReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public function __construct(\Rector\Core\PhpParser\Node\NodeFactory $nodeFactory
$this->valueResolver = $valueResolver;
}
/**
* @param MethodCall|StaticCall|ClassMethod|Expr\FuncCall $node
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\FuncCall $node
*/
public function processReplaces(\PhpParser\Node $node, \Rector\Arguments\Contract\ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue) : ?\PhpParser\Node
public function processReplaces($node, \Rector\Arguments\Contract\ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue) : ?\PhpParser\Node
{
if ($node instanceof \PhpParser\Node\Stmt\ClassMethod) {
if (!isset($node->params[$replaceArgumentDefaultValue->getPosition()])) {
Expand Down
4 changes: 2 additions & 2 deletions rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ private function processPositionWithDefaultValues($node, \Rector\Arguments\Value
}
}
/**
* @param ClassMethod|MethodCall|StaticCall $node
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node
*/
private function shouldSkipParameter(\PhpParser\Node $node, \Rector\Arguments\ValueObject\ArgumentAdder $argumentAdder) : bool
private function shouldSkipParameter($node, \Rector\Arguments\ValueObject\ArgumentAdder $argumentAdder) : bool
{
$position = $argumentAdder->getPosition();
$argumentName = $argumentAdder->getArgumentName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
Expand Down Expand Up @@ -73,9 +72,9 @@ public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
return $node;
}
/**
* @param ClassMethod|Function_ $functionLike
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
*/
private function matchFuncGetArgsVariableAssign(\PhpParser\Node\FunctionLike $functionLike) : ?\PhpParser\Node\Expr\Assign
private function matchFuncGetArgsVariableAssign($functionLike) : ?\PhpParser\Node\Expr\Assign
{
/** @var Assign[] $assigns */
$assigns = $this->betterNodeFinder->findInstanceOf((array) $functionLike->stmts, \PhpParser\Node\Expr\Assign::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ private function resolveCurrentStmtVariableName(\PhpParser\Node\Stmt $stmt) : ?s
return null;
}
/**
* @param ClassMethod|Function_|Closure $node
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node
*/
private function shouldAddEmptyLine(?string $currentStmtVariableName, \PhpParser\Node $node, int $key) : bool
private function shouldAddEmptyLine(?string $currentStmtVariableName, $node, int $key) : bool
{
if (!$this->isNewVariableThanBefore($currentStmtVariableName)) {
return \false;
Expand Down Expand Up @@ -148,9 +148,9 @@ private function isNewVariableThanBefore(?string $currentStmtVariableName) : boo
return $this->previousStmtVariableName !== $currentStmtVariableName;
}
/**
* @param ClassMethod|Function_|Closure $node
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node
*/
private function isPrecededByEmptyLine(\PhpParser\Node $node, int $key) : bool
private function isPrecededByEmptyLine($node, int $key) : bool
{
if ($node->stmts === null) {
return \false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\NullableType;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
Expand Down Expand Up @@ -96,9 +95,9 @@ private function isNullableParam(\PhpParser\Node\Param $param) : bool
return $param->type instanceof \PhpParser\Node\NullableType;
}
/**
* @param ClassMethod|Function_|Closure $functionLike
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
private function refactorParamType(\PhpParser\Node\Param $param, \PhpParser\Node\FunctionLike $functionLike) : bool
private function refactorParamType(\PhpParser\Node\Param $param, $functionLike) : bool
{
if (!$this->isNullableParam($param)) {
return \false;
Expand All @@ -108,9 +107,9 @@ private function refactorParamType(\PhpParser\Node\Param $param, \PhpParser\Node
return \true;
}
/**
* @param ClassMethod|Function_|Closure $functionLike
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
private function decorateWithDocBlock(\PhpParser\Node\FunctionLike $functionLike, \PhpParser\Node\Param $param) : void
private function decorateWithDocBlock($functionLike, \PhpParser\Node\Param $param) : void
{
if ($param->type === null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
Expand Down Expand Up @@ -47,10 +46,10 @@ public function __construct(\Rector\StaticTypeMapper\StaticTypeMapper $staticTyp
$this->typeUnwrapper = $typeUnwrapper;
}
/**
* @param ClassMethod|Function_|Closure $functionLike
* @return bool True if node was changed
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
public function decorate(\PhpParser\Node\FunctionLike $functionLike) : bool
public function decorate($functionLike) : bool
{
if ($functionLike->returnType === null) {
return \false;
Expand All @@ -62,10 +61,10 @@ public function decorate(\PhpParser\Node\FunctionLike $functionLike) : bool
return \true;
}
/**
* @param ClassMethod|Function_ $functionLike
* @param array<class-string<Type>> $requiredTypes
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
public function decorateParam(\PhpParser\Node\Param $param, \PhpParser\Node\FunctionLike $functionLike, array $requiredTypes) : void
public function decorateParam(\PhpParser\Node\Param $param, $functionLike, array $requiredTypes) : void
{
if ($param->type === null) {
return;
Expand All @@ -77,9 +76,9 @@ public function decorateParam(\PhpParser\Node\Param $param, \PhpParser\Node\Func
$this->moveParamTypeToParamDoc($functionLike, $param, $type);
}
/**
* @param ClassMethod|Function_ $functionLike
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
public function decorateParamWithSpecificType(\PhpParser\Node\Param $param, \PhpParser\Node\FunctionLike $functionLike, \PHPStan\Type\Type $requireType) : void
public function decorateParamWithSpecificType(\PhpParser\Node\Param $param, $functionLike, \PHPStan\Type\Type $requireType) : void
{
if ($param->type === null) {
return;
Expand All @@ -91,10 +90,10 @@ public function decorateParamWithSpecificType(\PhpParser\Node\Param $param, \Php
$this->moveParamTypeToParamDoc($functionLike, $param, $type);
}
/**
* @param ClassMethod|Function_|Closure $functionLike
* @return bool True if node was changed
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
public function decorateReturnWithSpecificType(\PhpParser\Node\FunctionLike $functionLike, \PHPStan\Type\Type $requireType) : bool
public function decorateReturnWithSpecificType($functionLike, \PHPStan\Type\Type $requireType) : bool
{
if ($functionLike->returnType === null) {
return \false;
Expand All @@ -114,9 +113,9 @@ private function isTypeMatchOrSubType(\PhpParser\Node $typeNode, \PHPStan\Type\T
return \is_a($returnType, \get_class($requireType), \true);
}
/**
* @param ClassMethod|Function_ $functionLike
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
private function moveParamTypeToParamDoc(\PhpParser\Node\FunctionLike $functionLike, \PhpParser\Node\Param $param, \PHPStan\Type\Type $type) : void
private function moveParamTypeToParamDoc($functionLike, \PhpParser\Node\Param $param, \PHPStan\Type\Type $type) : void
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
$paramName = $this->nodeNameResolver->getName($param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ private function getDifferentParamTypeFromReflectionMethod(\ReflectionMethod $re
return null;
}
/**
* @param ClassMethod|Function_ $functionLike
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
*/
private function refactorParam(\PhpParser\Node\Param $param, \PhpParser\Node\FunctionLike $functionLike) : void
private function refactorParam(\PhpParser\Node\Param $param, $functionLike) : void
{
if (!$this->isNullableParam($param, $functionLike)) {
return;
Expand All @@ -200,9 +200,9 @@ private function refactorParam(\PhpParser\Node\Param $param, \PhpParser\Node\Fun
$param->type = null;
}
/**
* @param ClassMethod|Function_ $functionLike
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
*/
private function decorateWithDocBlock(\PhpParser\Node\FunctionLike $functionLike, \PhpParser\Node\Param $param) : void
private function decorateWithDocBlock($functionLike, \PhpParser\Node\Param $param) : void
{
if ($param->type === null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ private function processUses(\PhpParser\Node\Expr\Closure $node) : void
$this->cleanTrailingComma($node, $node->uses);
}
/**
* @param ClassMethod|Function_|Closure $node
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node
*/
private function processParams(\PhpParser\Node $node) : ?\PhpParser\Node
private function processParams($node) : ?\PhpParser\Node
{
if ($node->params === []) {
return null;
Expand Down
13 changes: 6 additions & 7 deletions rules/Naming/Guard/BreakingVariableRenameGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Foreach_;
Expand Down Expand Up @@ -68,9 +67,9 @@ public function __construct(\Rector\Core\PhpParser\Node\BetterNodeFinder $better
$this->nodeNameResolver = $nodeNameResolver;
}
/**
* @param ClassMethod|Function_|Closure $functionLike
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
public function shouldSkipVariable(string $currentName, string $expectedName, \PhpParser\Node\FunctionLike $functionLike, \PhpParser\Node\Expr\Variable $variable) : bool
public function shouldSkipVariable(string $currentName, string $expectedName, $functionLike, \PhpParser\Node\Expr\Variable $variable) : bool
{
// is the suffix? → also accepted
$expectedNameCamelCase = \ucfirst($expectedName);
Expand Down Expand Up @@ -143,16 +142,16 @@ private function isVariableAlreadyDefined(\PhpParser\Node\Expr\Variable $variabl
return $trinaryLogic->maybe();
}
/**
* @param ClassMethod|Function_|Closure $functionLike
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
private function skipOnConflictOtherVariable(\PhpParser\Node\FunctionLike $functionLike, string $newName) : bool
private function skipOnConflictOtherVariable($functionLike, string $newName) : bool
{
return $this->betterNodeFinder->hasInstanceOfName((array) $functionLike->stmts, \PhpParser\Node\Expr\Variable::class, $newName);
}
/**
* @param ClassMethod|Function_|Closure $functionLike
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
private function isUsedInClosureUsesName(string $expectedName, \PhpParser\Node\FunctionLike $functionLike) : bool
private function isUsedInClosureUsesName(string $expectedName, $functionLike) : bool
{
if (!$functionLike instanceof \PhpParser\Node\Expr\Closure) {
return \false;
Expand Down
5 changes: 2 additions & 3 deletions rules/Naming/Matcher/ForeachMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare (strict_types=1);
namespace Rector\Naming\Matcher;

use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\ClassMethod;
Expand Down Expand Up @@ -52,9 +51,9 @@ public function match(\PhpParser\Node\Stmt\Foreach_ $foreach) : ?\Rector\Naming\
return new \Rector\Naming\ValueObject\VariableAndCallForeach($foreach->valueVar, $call, $variableName, $functionLike);
}
/**
* @return ClassMethod|Function_|Closure|null
* @return \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|null
*/
private function getFunctionLike(\PhpParser\Node\Stmt\Foreach_ $foreach) : ?\PhpParser\Node
private function getFunctionLike(\PhpParser\Node\Stmt\Foreach_ $foreach)
{
return $this->betterNodeFinder->findParentTypes($foreach, [\PhpParser\Node\Expr\Closure::class, \PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Stmt\Function_::class]);
}
Expand Down
5 changes: 2 additions & 3 deletions rules/Naming/Matcher/VariableAndCallAssignMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare (strict_types=1);
namespace Rector\Naming\Matcher;

use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Variable;
Expand Down Expand Up @@ -53,9 +52,9 @@ public function match(\PhpParser\Node\Expr\Assign $assign) : ?\Rector\Naming\Val
return new \Rector\Naming\ValueObject\VariableAndCallAssign($assign->var, $call, $assign, $variableName, $functionLike);
}
/**
* @return ClassMethod|Function_|Closure|null
* @return \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|null
*/
private function getFunctionLike(\PhpParser\Node\Expr\Assign $assign) : ?\PhpParser\Node
private function getFunctionLike(\PhpParser\Node\Expr\Assign $assign)
{
return $this->betterNodeFinder->findParentTypes($assign, [\PhpParser\Node\Expr\Closure::class, \PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Stmt\Function_::class]);
}
Expand Down
21 changes: 10 additions & 11 deletions rules/Naming/Naming/ConflictingNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
Expand Down Expand Up @@ -62,18 +61,18 @@ public function resolveConflictingVariableNamesForParam(\PhpParser\Node\Stmt\Cla
return $this->arrayFilter->filterWithAtLeastTwoOccurences($expectedNames);
}
/**
* @param ClassMethod|Function_|Closure $functionLike
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
public function checkNameIsInFunctionLike(string $variableName, \PhpParser\Node\FunctionLike $functionLike) : bool
public function checkNameIsInFunctionLike(string $variableName, $functionLike) : bool
{
$conflictingVariableNames = $this->resolveConflictingVariableNamesForNew($functionLike);
return \in_array($variableName, $conflictingVariableNames, \true);
}
/**
* @param ClassMethod|Function_|Closure $functionLike
* @return string[]
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
private function resolveConflictingVariableNamesForNew(\PhpParser\Node\FunctionLike $functionLike) : array
private function resolveConflictingVariableNamesForNew($functionLike) : array
{
// cache it!
$classMethodHash = \spl_object_hash($functionLike);
Expand All @@ -89,10 +88,10 @@ private function resolveConflictingVariableNamesForNew(\PhpParser\Node\FunctionL
return $protectedNames;
}
/**
* @param ClassMethod|Function_|Closure $functionLike
* @return string[]
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
private function collectParamNames(\PhpParser\Node\FunctionLike $functionLike) : array
private function collectParamNames($functionLike) : array
{
$paramNames = [];
// params
Expand All @@ -102,10 +101,10 @@ private function collectParamNames(\PhpParser\Node\FunctionLike $functionLike) :
return $paramNames;
}
/**
* @param ClassMethod|Function_|Closure $functionLike
* @return string[]
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
private function resolveForNewAssigns(\PhpParser\Node\FunctionLike $functionLike) : array
private function resolveForNewAssigns($functionLike) : array
{
$names = [];
/** @var Assign[] $assigns */
Expand All @@ -120,10 +119,10 @@ private function resolveForNewAssigns(\PhpParser\Node\FunctionLike $functionLike
return $names;
}
/**
* @param ClassMethod|Function_|Closure $functionLike
* @return string[]
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
private function resolveForNonNewAssigns(\PhpParser\Node\FunctionLike $functionLike) : array
private function resolveForNonNewAssigns($functionLike) : array
{
$names = [];
/** @var Assign[] $assigns */
Expand Down
Loading

0 comments on commit a7f25f1

Please sign in to comment.