mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 20:39:43 +01:00
Updated Rector to commit bfa1891c50677b01136a9308fd3c3ecc12e267d9
bfa1891c50
[cleanup] Remove 73 unused public methods (#3245)
This commit is contained in:
parent
680ba23c17
commit
727b9f46f0
@ -11,7 +11,6 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
|
||||
@ -177,15 +176,6 @@ final class PhpDocInfo
|
||||
{
|
||||
return $this->getTypeOrMixed($this->getReturnTagValue());
|
||||
}
|
||||
/**
|
||||
* @template TNode as \PHPStan\PhpDocParser\Ast\Node
|
||||
* @param class-string<TNode> $type
|
||||
* @return TNode[]
|
||||
*/
|
||||
public function getByType(string $type) : array
|
||||
{
|
||||
return $this->phpDocNodeByTypeFinder->findByType($this->phpDocNode, $type);
|
||||
}
|
||||
/**
|
||||
* @param class-string<Node> $type
|
||||
*/
|
||||
@ -233,6 +223,9 @@ final class PhpDocInfo
|
||||
$doctrineAnnotationTagValueNodes = $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClasses($this->phpDocNode, $classes);
|
||||
return $doctrineAnnotationTagValueNodes[0] ?? null;
|
||||
}
|
||||
/**
|
||||
* @api doctrine/symfony
|
||||
*/
|
||||
public function getByAnnotationClass(string $class) : ?DoctrineAnnotationTagValueNode
|
||||
{
|
||||
$doctrineAnnotationTagValueNodes = $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClass($this->phpDocNode, $class);
|
||||
@ -268,14 +261,6 @@ final class PhpDocInfo
|
||||
$foundTagValueNodes = $this->findByAnnotationClass($desiredClass);
|
||||
return $foundTagValueNodes[0] ?? null;
|
||||
}
|
||||
/**
|
||||
* @param class-string $desiredClass
|
||||
* @return DoctrineAnnotationTagValueNode[]
|
||||
*/
|
||||
public function findByAnnotationClass(string $desiredClass) : array
|
||||
{
|
||||
return $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClass($this->phpDocNode, $desiredClass);
|
||||
}
|
||||
/**
|
||||
* @template T of \PHPStan\PhpDocParser\Ast\Node
|
||||
* @param class-string<T> $typeToRemove
|
||||
@ -302,18 +287,6 @@ final class PhpDocInfo
|
||||
return PhpDocNodeTraverser::NODE_REMOVE;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @return array<string, Type>
|
||||
*/
|
||||
public function getParamTypesByName() : array
|
||||
{
|
||||
$paramTypesByName = [];
|
||||
foreach ($this->phpDocNode->getParamTagValues() as $paramTagValueNode) {
|
||||
$parameterType = $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType($paramTagValueNode, $this->node);
|
||||
$paramTypesByName[$paramTagValueNode->parameterName] = $parameterType;
|
||||
}
|
||||
return $paramTypesByName;
|
||||
}
|
||||
public function addTagValueNode(PhpDocTagValueNode $phpDocTagValueNode) : void
|
||||
{
|
||||
if ($phpDocTagValueNode instanceof DoctrineAnnotationTagValueNode) {
|
||||
@ -388,21 +361,6 @@ final class PhpDocInfo
|
||||
{
|
||||
return $this->phpDocNode->getTemplateTagValues();
|
||||
}
|
||||
public function hasInheritDoc() : bool
|
||||
{
|
||||
if ($this->hasByNames(['inheritdoc', 'inheritDoc'])) {
|
||||
return \true;
|
||||
}
|
||||
foreach ($this->phpDocNode->children as $children) {
|
||||
if (!$children instanceof PhpDocTextNode) {
|
||||
continue;
|
||||
}
|
||||
if (\in_array($children->text, ['{@inheritdoc}', '{@inheritDoc}'], \true)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* Should be handled by attributes of phpdoc node - if stard_and_end is missing in one of nodes, it has been changed
|
||||
@ -431,17 +389,6 @@ final class PhpDocInfo
|
||||
$phpDocNodeTraverser->traverse($this->phpDocNode);
|
||||
return $changedPhpDocNodeVisitor->hasChanged();
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getMethodTagNames() : array
|
||||
{
|
||||
$methodTagNames = [];
|
||||
foreach ($this->phpDocNode->getMethodTagValues() as $methodTagValueNode) {
|
||||
$methodTagNames[] = $methodTagValueNode->methodName;
|
||||
}
|
||||
return $methodTagNames;
|
||||
}
|
||||
public function makeMultiLined() : void
|
||||
{
|
||||
$this->isSingleLine = \false;
|
||||
@ -450,7 +397,7 @@ final class PhpDocInfo
|
||||
{
|
||||
return $this->node;
|
||||
}
|
||||
public function resolveNameForPhpDocTagValueNode(PhpDocTagValueNode $phpDocTagValueNode) : ?string
|
||||
private function resolveNameForPhpDocTagValueNode(PhpDocTagValueNode $phpDocTagValueNode) : ?string
|
||||
{
|
||||
foreach (self::TAGS_TYPES_TO_NAMES as $tagValueNodeType => $name) {
|
||||
/** @var class-string<PhpDocTagNode> $tagValueNodeType */
|
||||
@ -460,6 +407,14 @@ final class PhpDocInfo
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param class-string $desiredClass
|
||||
* @return DoctrineAnnotationTagValueNode[]
|
||||
*/
|
||||
private function findByAnnotationClass(string $desiredClass) : array
|
||||
{
|
||||
return $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClass($this->phpDocNode, $desiredClass);
|
||||
}
|
||||
/**
|
||||
* @return \PHPStan\Type\MixedType|\PHPStan\Type\Type
|
||||
*/
|
||||
|
@ -221,6 +221,9 @@ final class PhpDocTypeChanger
|
||||
$this->changeParamType($phpDocInfo, $paramType, $param, $paramVarName);
|
||||
$this->processKeepComments($property, $param);
|
||||
}
|
||||
/**
|
||||
* @api doctrine
|
||||
*/
|
||||
public function changeVarTypeNode(PhpDocInfo $phpDocInfo, TypeNode $typeNode) : void
|
||||
{
|
||||
// add completely new one
|
||||
|
@ -4,15 +4,9 @@ declare (strict_types=1);
|
||||
namespace Rector\BetterPhpDocParser\PhpDocManipulator;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
final class VarAnnotationManipulator
|
||||
{
|
||||
/**
|
||||
@ -25,28 +19,10 @@ final class VarAnnotationManipulator
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger
|
||||
*/
|
||||
private $phpDocTypeChanger;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
public function __construct(PhpDocInfoFactory $phpDocInfoFactory, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger $phpDocTypeChanger, BetterNodeFinder $betterNodeFinder)
|
||||
public function __construct(PhpDocInfoFactory $phpDocInfoFactory, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger $phpDocTypeChanger)
|
||||
{
|
||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
}
|
||||
public function decorateNodeWithInlineVarType(Node $node, TypeWithClassName $typeWithClassName, string $variableName) : void
|
||||
{
|
||||
$phpDocInfo = $this->resolvePhpDocInfo($node);
|
||||
// already done
|
||||
if ($phpDocInfo->getVarTagValueNode() !== null) {
|
||||
return;
|
||||
}
|
||||
$fullyQualifiedIdentifierTypeNode = new FullyQualifiedIdentifierTypeNode($typeWithClassName->getClassName());
|
||||
$varTagValueNode = new VarTagValueNode($fullyQualifiedIdentifierTypeNode, '$' . $variableName, '');
|
||||
$phpDocInfo->addTagValueNode($varTagValueNode);
|
||||
$phpDocInfo->makeSingleLined();
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
@ -59,15 +35,4 @@ final class VarAnnotationManipulator
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
||||
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $staticType);
|
||||
}
|
||||
private function resolvePhpDocInfo(Node $node) : PhpDocInfo
|
||||
{
|
||||
$currentStmt = $this->betterNodeFinder->resolveCurrentStatement($node);
|
||||
if ($currentStmt instanceof Expression) {
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($currentStmt);
|
||||
} else {
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
||||
}
|
||||
$phpDocInfo->makeSingleLined();
|
||||
return $phpDocInfo;
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,9 @@ final class ClassAnnotationMatcher
|
||||
$this->useImportsResolver = $useImportsResolver;
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
}
|
||||
/**
|
||||
* @api doctrine
|
||||
*/
|
||||
public function resolveTagToKnownFullyQualifiedName(string $tag, Property $property) : ?string
|
||||
{
|
||||
return $this->_resolveTagFullyQualifiedName($tag, $property, \true);
|
||||
|
@ -50,6 +50,7 @@ final class StaticDoctrineAnnotationParser
|
||||
return $this->resolveAnnotationValues($tokenIterator);
|
||||
}
|
||||
/**
|
||||
* @api tests
|
||||
* @see https://github.com/doctrine/annotations/blob/c66f06b7c83e9a2a7523351a9d5a4b55f885e574/lib/Doctrine/Common/Annotations/DocParser.php#L1215-L1224
|
||||
* @return CurlyListNode|string|array<mixed>|ConstExprNode|DoctrineAnnotationTagValueNode
|
||||
*/
|
||||
|
@ -143,7 +143,7 @@ final class PhpDocInfoPrinter
|
||||
// hotfix of extra space with callable ()
|
||||
return Strings::replace($phpDocString, self::CALLABLE_REGEX, 'callable(');
|
||||
}
|
||||
public function getCurrentPhpDocInfo() : PhpDocInfo
|
||||
private function getCurrentPhpDocInfo() : PhpDocInfo
|
||||
{
|
||||
if ($this->phpDocInfo === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
|
@ -80,28 +80,6 @@ final class BetterTokenIterator extends TokenIterator
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
public function print() : string
|
||||
{
|
||||
$content = '';
|
||||
foreach ($this->getTokens() as $token) {
|
||||
$content .= $token[0];
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
public function nextTokenType() : ?int
|
||||
{
|
||||
$tokens = $this->getTokens();
|
||||
// does next token exist?
|
||||
$nextIndex = $this->currentPosition() + 1;
|
||||
if (!isset($tokens[$nextIndex])) {
|
||||
return null;
|
||||
}
|
||||
$this->pushSavePoint();
|
||||
$this->next();
|
||||
$nextTokenType = $this->currentTokenType();
|
||||
$this->rollback();
|
||||
return $nextTokenType;
|
||||
}
|
||||
public function currentPosition() : int
|
||||
{
|
||||
return $this->privatesAccessor->getPrivateProperty($this, self::INDEX);
|
||||
@ -133,4 +111,18 @@ final class BetterTokenIterator extends TokenIterator
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function nextTokenType() : ?int
|
||||
{
|
||||
$tokens = $this->getTokens();
|
||||
// does next token exist?
|
||||
$nextIndex = $this->currentPosition() + 1;
|
||||
if (!isset($tokens[$nextIndex])) {
|
||||
return null;
|
||||
}
|
||||
$this->pushSavePoint();
|
||||
$this->next();
|
||||
$nextTokenType = $this->currentTokenType();
|
||||
$this->rollback();
|
||||
return $nextTokenType;
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,9 @@ abstract class AbstractValuesAwareNode implements PhpDocTagValueNode
|
||||
$this->originalContent = $originalContent;
|
||||
$this->silentKey = $silentKey;
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public function removeValue(string $desiredKey) : void
|
||||
{
|
||||
foreach ($this->values as $key => $value) {
|
||||
|
@ -32,11 +32,4 @@ final class StartAndEnd
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
public function contains(int $position) : bool
|
||||
{
|
||||
if ($position < $this->start) {
|
||||
return \false;
|
||||
}
|
||||
return $position < $this->end;
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,9 @@ final class CacheFactory
|
||||
$this->parameterProvider = $parameterProvider;
|
||||
$this->fileSystem = $fileSystem;
|
||||
}
|
||||
/**
|
||||
* @api config factory
|
||||
*/
|
||||
public function create() : \Rector\Caching\Cache
|
||||
{
|
||||
$cacheDirectory = $this->parameterProvider->provideStringParameter(Option::CACHE_DIR);
|
||||
|
@ -44,10 +44,6 @@ final class RectorWithLineChange implements SerializableInterface
|
||||
{
|
||||
return $this->rectorClass;
|
||||
}
|
||||
public function getLine() : int
|
||||
{
|
||||
return $this->line;
|
||||
}
|
||||
/**
|
||||
* @param array<string, mixed> $json
|
||||
* @return $this
|
||||
|
@ -13,6 +13,9 @@ use PhpParser\Node\Name;
|
||||
*/
|
||||
final class FluentChainMethodCallNodeAnalyzer
|
||||
{
|
||||
/**
|
||||
* @api doctrine
|
||||
*/
|
||||
public function resolveRootMethodCall(MethodCall $methodCall) : ?MethodCall
|
||||
{
|
||||
$callerNode = $methodCall->var;
|
||||
|
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Defluent\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
final class SameClassMethodCallAnalyzer
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Reflection\ReflectionResolver
|
||||
*/
|
||||
private $reflectionResolver;
|
||||
public function __construct(ReflectionResolver $reflectionResolver)
|
||||
{
|
||||
$this->reflectionResolver = $reflectionResolver;
|
||||
}
|
||||
/**
|
||||
* @param MethodCall[] $chainMethodCalls
|
||||
*/
|
||||
public function haveSingleClass(array $chainMethodCalls) : bool
|
||||
{
|
||||
// are method calls located in the same class?
|
||||
$classOfClassMethod = [];
|
||||
foreach ($chainMethodCalls as $chainMethodCall) {
|
||||
$methodReflection = $this->reflectionResolver->resolveMethodReflectionFromMethodCall($chainMethodCall);
|
||||
if ($methodReflection instanceof MethodReflection) {
|
||||
$declaringClass = $methodReflection->getDeclaringClass();
|
||||
$classOfClassMethod[] = $declaringClass->getName();
|
||||
} else {
|
||||
$classOfClassMethod[] = null;
|
||||
}
|
||||
}
|
||||
$uniqueClasses = \array_unique($classOfClassMethod);
|
||||
return \count($uniqueClasses) < 2;
|
||||
}
|
||||
}
|
@ -58,6 +58,9 @@ final class ClassChildAnalyzer
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* @api downgrade
|
||||
*/
|
||||
public function resolveParentClassMethodReturnType(ClassReflection $classReflection, string $methodName) : Type
|
||||
{
|
||||
$parentClassMethods = $this->resolveParentClassMethods($classReflection, $methodName);
|
||||
@ -76,7 +79,7 @@ final class ClassChildAnalyzer
|
||||
/**
|
||||
* @return PhpMethodReflection[]
|
||||
*/
|
||||
public function resolveParentClassMethods(ClassReflection $classReflection, string $methodName) : array
|
||||
private function resolveParentClassMethods(ClassReflection $classReflection, string $methodName) : array
|
||||
{
|
||||
$parentClassMethods = [];
|
||||
$parents = \array_merge($classReflection->getParents(), $classReflection->getInterfaces());
|
||||
|
@ -36,6 +36,7 @@ final class FileInfoParser
|
||||
$this->rectorParser = $rectorParser;
|
||||
}
|
||||
/**
|
||||
* @api tests only
|
||||
* @return Stmt[]
|
||||
*/
|
||||
public function parseFileInfoToNodesAndDecorate(string $filePath) : array
|
||||
|
@ -5,6 +5,9 @@ namespace Rector\FileSystemRector\ValueObject;
|
||||
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\FileSystemRector\Contract\AddedFileInterface;
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
final class AddedFileWithContent implements AddedFileInterface
|
||||
{
|
||||
/**
|
||||
|
@ -5,6 +5,9 @@ namespace Rector\NodeCollector\ValueObject;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use Rector\Core\Validation\RectorAssert;
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
final class ArrayCallableDynamicMethod
|
||||
{
|
||||
/**
|
||||
|
@ -182,14 +182,6 @@ final class NodeNameResolver
|
||||
{
|
||||
return $this->classNaming->getShortName($name);
|
||||
}
|
||||
/**
|
||||
* @param array<string, string> $renameMap
|
||||
*/
|
||||
public function matchNameFromMap(Node $node, array $renameMap) : ?string
|
||||
{
|
||||
$name = $this->getName($node);
|
||||
return $renameMap[$name] ?? null;
|
||||
}
|
||||
public function isStringName(string $resolvedName, string $desiredName) : bool
|
||||
{
|
||||
if ($desiredName === '') {
|
||||
|
@ -8,7 +8,6 @@ use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\Else_;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\Core\PhpParser\Comparing\NodeComparator;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\NodeNestingScope\ValueObject\ControlStructure;
|
||||
@ -33,17 +32,6 @@ final class ScopeNestingComparator
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->nodeComparator = $nodeComparator;
|
||||
}
|
||||
public function areReturnScopeNested(Return_ $return, Node $secondNodeScopeNode) : bool
|
||||
{
|
||||
$firstNodeScopeNode = $this->betterNodeFinder->findParentByTypes($return, ControlStructure::RETURN_ISOLATING_SCOPE_NODE_TYPES);
|
||||
return $this->nodeComparator->areNodesEqual($firstNodeScopeNode, $secondNodeScopeNode);
|
||||
}
|
||||
public function areScopeNestingEqual(Node $firstNode, Node $secondNode) : bool
|
||||
{
|
||||
$firstNodeScopeNode = $this->findParentControlStructure($firstNode);
|
||||
$secondNodeScopeNode = $this->findParentControlStructure($secondNode);
|
||||
return $this->nodeComparator->areNodesEqual($firstNodeScopeNode, $secondNodeScopeNode);
|
||||
}
|
||||
public function isNodeConditionallyScoped(Expr $expr) : bool
|
||||
{
|
||||
$foundParent = $this->betterNodeFinder->findParentByTypes($expr, ControlStructure::CONDITIONAL_NODE_SCOPE_TYPES + [FunctionLike::class]);
|
||||
@ -62,7 +50,7 @@ final class ScopeNestingComparator
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
public function isInBothIfElseBranch(Node $foundParentNode, Expr $seekedExpr) : bool
|
||||
private function isInBothIfElseBranch(Node $foundParentNode, Expr $seekedExpr) : bool
|
||||
{
|
||||
if ($foundParentNode instanceof Else_) {
|
||||
return $this->nodeComparator->isNodeEqual($seekedExpr, $this->doubleIfBranchExprs);
|
||||
@ -85,8 +73,4 @@ final class ScopeNestingComparator
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function findParentControlStructure(Node $node) : ?Node
|
||||
{
|
||||
return $this->betterNodeFinder->findParentByTypes($node, ControlStructure::BREAKING_SCOPE_NODE_TYPES);
|
||||
}
|
||||
}
|
||||
|
@ -4,28 +4,20 @@ declare (strict_types=1);
|
||||
namespace Rector\NodeNestingScope\ValueObject;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ArrowFunction;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\Match_;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\Case_;
|
||||
use PhpParser\Node\Stmt\Catch_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Do_;
|
||||
use PhpParser\Node\Stmt\Else_;
|
||||
use PhpParser\Node\Stmt\ElseIf_;
|
||||
use PhpParser\Node\Stmt\For_;
|
||||
use PhpParser\Node\Stmt\Foreach_;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PhpParser\Node\Stmt\Switch_;
|
||||
use PhpParser\Node\Stmt\While_;
|
||||
final class ControlStructure
|
||||
{
|
||||
/**
|
||||
* @var array<class-string<FunctionLike>>
|
||||
*/
|
||||
public const RETURN_ISOLATING_SCOPE_NODE_TYPES = [Function_::class, ClassMethod::class, Closure::class, ArrowFunction::class];
|
||||
/**
|
||||
* @var array<class-string<Node>>
|
||||
*/
|
||||
|
@ -66,18 +66,6 @@ final class NodeRemover
|
||||
$this->removeNode($node);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
public function removeStmt($functionLike, int $key) : void
|
||||
{
|
||||
if ($functionLike->stmts === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
// notify about remove node
|
||||
$this->rectorChangeCollector->notifyNodeFileInfo($functionLike->stmts[$key]);
|
||||
unset($functionLike->stmts[$key]);
|
||||
}
|
||||
/**
|
||||
* @param int|\PhpParser\Node\Param $keyOrParam
|
||||
*/
|
||||
@ -111,4 +99,17 @@ final class NodeRemover
|
||||
$this->rectorChangeCollector->notifyNodeFileInfo($node->args[$key]);
|
||||
unset($node->args[$key]);
|
||||
}
|
||||
/**
|
||||
* @api phpunit
|
||||
* @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
public function removeStmt($functionLike, int $key) : void
|
||||
{
|
||||
if ($functionLike->stmts === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
// notify about remove node
|
||||
$this->rectorChangeCollector->notifyNodeFileInfo($functionLike->stmts[$key]);
|
||||
unset($functionLike->stmts[$key]);
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ final class NodeTypeResolver
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @api doctrine symfony
|
||||
* @param ObjectType[] $requiredTypes
|
||||
*/
|
||||
public function isObjectTypes(Node $node, array $requiredTypes) : bool
|
||||
|
@ -7,6 +7,9 @@ use PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
|
||||
use PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator;
|
||||
use PHPStan\Reflection\BetterReflection\BetterReflectionSourceLocatorFactory;
|
||||
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator\IntermediateSourceLocator;
|
||||
/**
|
||||
* @api used on phpstan config factory
|
||||
*/
|
||||
final class RectorBetterReflectionSourceLocatorFactory
|
||||
{
|
||||
/**
|
||||
|
@ -12,6 +12,9 @@ use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceL
|
||||
use Rector\NodeTypeResolver\Contract\SourceLocatorProviderInterface;
|
||||
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
|
||||
use RectorPrefix202212\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @api phpstan external
|
||||
*/
|
||||
final class DynamicSourceLocatorProvider implements SourceLocatorProviderInterface
|
||||
{
|
||||
/**
|
||||
|
@ -21,6 +21,7 @@ final class MethodTypeAnalyzer
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
}
|
||||
/**
|
||||
* @api downgrade
|
||||
* @param class-string $expectedClass
|
||||
* @param non-empty-string $expectedMethod
|
||||
*/
|
||||
|
@ -126,7 +126,7 @@ final class WorkerRunner
|
||||
* @param array{system_errors: SystemError[], file_diffs: FileDiff[]}|mixed[] $errorAndFileDiffs
|
||||
* @return array{system_errors: SystemError[], file_diffs: FileDiff[]}
|
||||
*/
|
||||
public function processFiles(File $file, Configuration $configuration, array $errorAndFileDiffs) : array
|
||||
private function processFiles(File $file, Configuration $configuration, array $errorAndFileDiffs) : array
|
||||
{
|
||||
foreach ($this->fileProcessors as $fileProcessor) {
|
||||
if (!$fileProcessor->supports($file, $configuration)) {
|
||||
|
@ -21,6 +21,9 @@ final class DoctrineAnnotationFactory
|
||||
{
|
||||
$this->nodePrinter = $nodePrinter;
|
||||
}
|
||||
/**
|
||||
* @api downgrade
|
||||
*/
|
||||
public function createFromAttribute(Attribute $attribute, string $className) : DoctrineAnnotationTagValueNode
|
||||
{
|
||||
$items = $this->createItemsFromArgs($attribute->args);
|
||||
|
@ -65,6 +65,7 @@ final class PhpAttributeGroupFactory
|
||||
return new AttributeGroup([$attribute]);
|
||||
}
|
||||
/**
|
||||
* @api tests
|
||||
* @param mixed[] $items
|
||||
*/
|
||||
public function createFromClassWithItems(string $attributeClass, array $items) : AttributeGroup
|
||||
@ -89,6 +90,8 @@ final class PhpAttributeGroupFactory
|
||||
return new AttributeGroup([$attribute]);
|
||||
}
|
||||
/**
|
||||
* @api tests
|
||||
*
|
||||
* @param ArrayItemNode[]|mixed[] $items
|
||||
* @return Arg[]
|
||||
*/
|
||||
|
@ -105,7 +105,7 @@ final class PhpNestedAttributeGroupFactory
|
||||
/**
|
||||
* @return Arg[]
|
||||
*/
|
||||
public function createAttributeArgs(DoctrineAnnotationTagValueNode $nestedDoctrineAnnotationTagValueNode, NestedAnnotationToAttribute $nestedAnnotationToAttribute) : array
|
||||
private function createAttributeArgs(DoctrineAnnotationTagValueNode $nestedDoctrineAnnotationTagValueNode, NestedAnnotationToAttribute $nestedAnnotationToAttribute) : array
|
||||
{
|
||||
$args = $this->createArgsFromItems($nestedDoctrineAnnotationTagValueNode->getValues(), $nestedAnnotationToAttribute);
|
||||
return $this->attributeArrayNameInliner->inlineArrayToArgs($args);
|
||||
|
@ -131,6 +131,7 @@ final class NodesToAddCollector implements NodeCollectorInterface
|
||||
unset($this->nodesToAddBefore[$objectHash]);
|
||||
}
|
||||
/**
|
||||
* @api downgrade
|
||||
* @deprecated Return created nodes right in refactor() method to keep context instead.
|
||||
* @param Node[] $newNodes
|
||||
*/
|
||||
|
@ -92,7 +92,6 @@ final class UseAddingPostRector extends \Rector\PostRector\Rector\AbstractPostRe
|
||||
$namespace = $this->betterNodeFinder->findFirstInstanceOf($nodes, Namespace_::class);
|
||||
if ($namespace instanceof Namespace_) {
|
||||
// first clean
|
||||
//$this->useImportsRemover->removeImportsFromNamespace($namespace, $removedShortUses);
|
||||
// then add, to prevent adding + removing false positive of same short use
|
||||
$this->useImportsAdder->addImportsToNamespace($namespace, $useImportTypes, $functionUseImportTypes);
|
||||
return $nodes;
|
||||
|
@ -10,6 +10,9 @@ use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
final class AliasedObjectType extends ObjectType
|
||||
{
|
||||
/**
|
||||
|
@ -9,6 +9,9 @@ use PhpParser\Node\Stmt\Use_;
|
||||
use PhpParser\Node\Stmt\UseUse;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
final class FullyQualifiedObjectType extends ObjectType
|
||||
{
|
||||
public function getShortNameType() : \Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType
|
||||
|
@ -6,6 +6,9 @@ namespace Rector\StaticTypeMapper\ValueObject\Type;
|
||||
use PHPStan\TrinaryLogic;
|
||||
use PHPStan\Type\Generic\GenericObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
final class ShortenedGenericObjectType extends GenericObjectType
|
||||
{
|
||||
/**
|
||||
@ -30,11 +33,4 @@ final class ShortenedGenericObjectType extends GenericObjectType
|
||||
{
|
||||
return $this->getClassName();
|
||||
}
|
||||
/**
|
||||
* @return class-string
|
||||
*/
|
||||
public function getFullyQualifiedName() : string
|
||||
{
|
||||
return $this->fullyQualifiedName;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,9 @@ namespace Rector\StaticTypeMapper\ValueObject\Type;
|
||||
use PHPStan\TrinaryLogic;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
final class ShortenedObjectType extends ObjectType
|
||||
{
|
||||
/**
|
||||
|
@ -6,6 +6,9 @@ namespace Rector\Testing\Fixture;
|
||||
use RectorPrefix202212\Nette\Utils\FileSystem;
|
||||
final class FixtureFileUpdater
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public static function updateFixtureContent(string $originalFilePath, string $changedContent, string $fixtureFilePath) : void
|
||||
{
|
||||
if (!\getenv('UPDATE_TESTS') && !\getenv('UT')) {
|
||||
|
@ -9,6 +9,7 @@ use RectorPrefix202212\Webmozart\Assert\Assert;
|
||||
final class FixtureSplitter
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
* @see https://regex101.com/r/zZDoyy/1
|
||||
*/
|
||||
|
@ -7,6 +7,7 @@ use RectorPrefix202212\Nette\Utils\FileSystem;
|
||||
final class FixtureTempFileDumper
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const TEMP_FIXTURE_DIRECTORY = '/rector/tests_fixture_';
|
||||
@ -17,6 +18,9 @@ final class FixtureTempFileDumper
|
||||
FileSystem::write($temporaryFileName, $fileContents);
|
||||
return $temporaryFileName;
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public static function getTempDirectory() : string
|
||||
{
|
||||
return \sys_get_temp_dir() . self::TEMP_FIXTURE_DIRECTORY;
|
||||
|
@ -52,7 +52,7 @@ final class ArgumentDefaultValueReplacer
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function isDefaultValueMatched(?Expr $expr, $value) : bool
|
||||
private function isDefaultValueMatched(?Expr $expr, $value) : bool
|
||||
{
|
||||
// allow any values before, also allow param without default value
|
||||
if ($value === ReplaceArgumentDefaultValue::ANY_VALUE_BEFORE) {
|
||||
|
@ -61,6 +61,7 @@ final class PropertyTypeDecorator
|
||||
$this->decoratePropertyWithType($property, $propertyType);
|
||||
}
|
||||
/**
|
||||
* @api downgrade
|
||||
* @param \PhpParser\Node\ComplexType|\PhpParser\Node\Identifier|\PhpParser\Node\Name $typeNode
|
||||
*/
|
||||
public function decoratePropertyWithDocBlock(Property $property, $typeNode) : void
|
||||
|
@ -101,9 +101,10 @@ CODE_SAMPLE
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function resolvePossibleGetMethodNames(string $propertyName) : array
|
||||
private function resolvePossibleGetMethodNames(string $propertyName) : array
|
||||
{
|
||||
return ['get' . \ucfirst($propertyName), 'has' . \ucfirst($propertyName), 'is' . \ucfirst($propertyName)];
|
||||
$upperPropertyName = \ucfirst($propertyName);
|
||||
return ['get' . $upperPropertyName, 'has' . $upperPropertyName, 'is' . $upperPropertyName];
|
||||
}
|
||||
private function shouldSkipPropertyFetch(PropertyFetch $propertyFetch) : bool
|
||||
{
|
||||
|
@ -4,7 +4,6 @@ declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Application;
|
||||
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
final class UseImportsRemover
|
||||
{
|
||||
@ -27,22 +26,6 @@ final class UseImportsRemover
|
||||
}
|
||||
return $stmts;
|
||||
}
|
||||
/**
|
||||
* @param string[] $removedShortUses
|
||||
*/
|
||||
public function removeImportsFromNamespace(Namespace_ $namespace, array $removedShortUses) : void
|
||||
{
|
||||
foreach ($namespace->stmts as $namespaceKey => $stmt) {
|
||||
if (!$stmt instanceof Use_) {
|
||||
continue;
|
||||
}
|
||||
$this->removeUseFromUse($removedShortUses, $stmt);
|
||||
// nothing left → remove
|
||||
if ($stmt->uses === []) {
|
||||
unset($namespace->stmts[$namespaceKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param string[] $removedShortUses
|
||||
*/
|
||||
|
@ -9,14 +9,6 @@ use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
final class ClassNaming
|
||||
{
|
||||
/**
|
||||
* @param string|\PhpParser\Node\Name|\PhpParser\Node\Identifier $name
|
||||
*/
|
||||
public function getVariableName($name) : string
|
||||
{
|
||||
$shortName = $this->getShortName($name);
|
||||
return \lcfirst($shortName);
|
||||
}
|
||||
/**
|
||||
* @param string|\PhpParser\Node\Name|\PhpParser\Node\Identifier|\PhpParser\Node\Stmt\ClassLike $name
|
||||
*/
|
||||
|
@ -63,7 +63,7 @@ final class UseImportNameMatcher
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function resolveName(string $prefix, string $tag, UseUse $useUse) : string
|
||||
private function resolveName(string $prefix, string $tag, UseUse $useUse) : string
|
||||
{
|
||||
// useuse can be renamed on the fly, so just in case, use the original one
|
||||
$originalUseUse = $useUse->getAttribute(AttributeKey::ORIGINAL_NODE);
|
||||
|
@ -70,10 +70,23 @@ CODE_SAMPLE
|
||||
$exprsToConcat = $this->createExpressionsToConcat($parts);
|
||||
return $this->nodeFactory->createConcat($exprsToConcat);
|
||||
}
|
||||
/**
|
||||
* @param string[] $classNames
|
||||
* @return mixed[]
|
||||
*/
|
||||
private function getParts(String_ $string, array $classNames) : array
|
||||
{
|
||||
$quotedClassNames = \array_map('preg_quote', $classNames);
|
||||
// @see https://regex101.com/r/8nGS0F/1
|
||||
$parts = Strings::split($string->value, '#(' . \implode('|', $quotedClassNames) . ')#');
|
||||
return \array_filter($parts, static function (string $className) : bool {
|
||||
return $className !== '';
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getExistingClasses(String_ $string) : array
|
||||
private function getExistingClasses(String_ $string) : array
|
||||
{
|
||||
/** @var mixed[] $matches */
|
||||
$matches = Strings::matchAll($string->value, self::CLASS_BEFORE_STATIC_ACCESS_REGEX, \PREG_PATTERN_ORDER);
|
||||
@ -89,19 +102,6 @@ CODE_SAMPLE
|
||||
}
|
||||
return $classNames;
|
||||
}
|
||||
/**
|
||||
* @param string[] $classNames
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getParts(String_ $string, array $classNames) : array
|
||||
{
|
||||
$quotedClassNames = \array_map('preg_quote', $classNames);
|
||||
// @see https://regex101.com/r/8nGS0F/1
|
||||
$parts = Strings::split($string->value, '#(' . \implode('|', $quotedClassNames) . ')#');
|
||||
return \array_filter($parts, static function (string $className) : bool {
|
||||
return $className !== '';
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param string[] $parts
|
||||
* @return ClassConstFetch[]|String_[]
|
||||
|
@ -39,10 +39,6 @@ final class PropertyWithPhpDocInfo
|
||||
{
|
||||
return $this->phpDocInfo;
|
||||
}
|
||||
public function getPropertyName() : string
|
||||
{
|
||||
return $this->propertyName;
|
||||
}
|
||||
public function getParamTagValueNode() : ParamTagValueNode
|
||||
{
|
||||
$varTagValueNode = $this->phpDocInfo->getVarTagValueNode();
|
||||
|
@ -56,6 +56,9 @@ final class PropertyConstructorInjectionManipulator
|
||||
$this->propertyToAddCollector = $propertyToAddCollector;
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
}
|
||||
/**
|
||||
* @api symfony
|
||||
*/
|
||||
public function refactor(Property $property, Type $type, DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : void
|
||||
{
|
||||
$propertyName = $this->nodeNameResolver->getName($property);
|
||||
|
@ -39,7 +39,7 @@ final class MatchPropertyTypeConflictingNameGuard
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function resolve(ClassLike $classLike) : array
|
||||
private function resolve(ClassLike $classLike) : array
|
||||
{
|
||||
$expectedNames = [];
|
||||
foreach ($classLike->getProperties() as $property) {
|
||||
|
@ -113,6 +113,7 @@ final class PropertyNaming
|
||||
return $this->prolongIfTooShort($variableName, $className);
|
||||
}
|
||||
/**
|
||||
* @api symfony
|
||||
* @see https://stackoverflow.com/a/2792045/1348344
|
||||
*/
|
||||
public function underscoreToName(string $underscoreName) : string
|
||||
|
@ -87,7 +87,7 @@ final class VariableNaming
|
||||
$bareName = $this->resolveBareFuncCallArgumentName($funcCall, $fallbackName, $suffix);
|
||||
return $this->createCountedValueName($bareName, $scope);
|
||||
}
|
||||
public function resolveFromNodeAndType(Node $node, Type $type) : ?string
|
||||
private function resolveFromNodeAndType(Node $node, Type $type) : ?string
|
||||
{
|
||||
$variableName = $this->resolveBareFromNode($node);
|
||||
if ($variableName === null) {
|
||||
|
@ -39,7 +39,7 @@ final class FileInfoDeletionAnalyzer
|
||||
$classShortName = $this->classNaming->getShortName($className);
|
||||
return $baseFileName === $classShortName;
|
||||
}
|
||||
public function clearNameFromTestingPrefix(string $name) : string
|
||||
private function clearNameFromTestingPrefix(string $name) : string
|
||||
{
|
||||
return Strings::replace($name, self::TESTING_PREFIX_REGEX, '');
|
||||
}
|
||||
|
@ -23,6 +23,9 @@ final class ClassFromEnumFactory
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
/**
|
||||
* @api downgrade
|
||||
*/
|
||||
public function createFromEnum(Enum_ $enum) : Class_
|
||||
{
|
||||
$shortClassName = $this->nodeNameResolver->getShortName($enum);
|
||||
|
@ -41,13 +41,6 @@ final class VisibilityManipulator
|
||||
}
|
||||
$node->flags -= Class_::MODIFIER_STATIC;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Class_ $node
|
||||
*/
|
||||
public function makeAbstract($node) : void
|
||||
{
|
||||
$this->addVisibilityFlag($node, Visibility::ABSTRACT);
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Class_ $node
|
||||
@ -77,27 +70,6 @@ final class VisibilityManipulator
|
||||
}
|
||||
$node->flags -= Class_::MODIFIER_FINAL;
|
||||
}
|
||||
/**
|
||||
* This way "abstract", "static", "final" are kept
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassConst $node
|
||||
*/
|
||||
public function removeVisibility($node) : void
|
||||
{
|
||||
// no modifier
|
||||
if ($node->flags === 0) {
|
||||
return;
|
||||
}
|
||||
if ($node->isPublic()) {
|
||||
$node->flags |= Class_::MODIFIER_PUBLIC;
|
||||
$node->flags -= Class_::MODIFIER_PUBLIC;
|
||||
}
|
||||
if ($node->isProtected()) {
|
||||
$node->flags -= Class_::MODIFIER_PROTECTED;
|
||||
}
|
||||
if ($node->isPrivate()) {
|
||||
$node->flags -= Class_::MODIFIER_PRIVATE;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassConst $node
|
||||
*/
|
||||
@ -135,6 +107,9 @@ final class VisibilityManipulator
|
||||
{
|
||||
$node->flags -= Class_::MODIFIER_FINAL;
|
||||
}
|
||||
/**
|
||||
* @api downgrade
|
||||
*/
|
||||
public function removeAbstract(ClassMethod $classMethod) : void
|
||||
{
|
||||
$classMethod->flags -= Class_::MODIFIER_ABSTRACT;
|
||||
@ -160,6 +135,27 @@ final class VisibilityManipulator
|
||||
{
|
||||
$this->removeVisibilityFlag($node, Visibility::READONLY);
|
||||
}
|
||||
/**
|
||||
* This way "abstract", "static", "final" are kept
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassConst $node
|
||||
*/
|
||||
private function removeVisibility($node) : void
|
||||
{
|
||||
// no modifier
|
||||
if ($node->flags === 0) {
|
||||
return;
|
||||
}
|
||||
if ($node->isPublic()) {
|
||||
$node->flags |= Class_::MODIFIER_PUBLIC;
|
||||
$node->flags -= Class_::MODIFIER_PUBLIC;
|
||||
}
|
||||
if ($node->isProtected()) {
|
||||
$node->flags -= Class_::MODIFIER_PROTECTED;
|
||||
}
|
||||
if ($node->isPrivate()) {
|
||||
$node->flags -= Class_::MODIFIER_PRIVATE;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassConst|\PhpParser\Node\Param $node
|
||||
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Renaming\Collector;
|
||||
|
||||
use Rector\Renaming\Contract\MethodCallRenameInterface;
|
||||
final class MethodCallRenameCollector
|
||||
{
|
||||
/**
|
||||
* @var MethodCallRenameInterface[]
|
||||
*/
|
||||
private $methodCallRenames = [];
|
||||
/**
|
||||
* @param MethodCallRenameInterface[] $methodCallRenames
|
||||
*/
|
||||
public function addMethodCallRenames(array $methodCallRenames) : void
|
||||
{
|
||||
$this->methodCallRenames = \array_merge($this->methodCallRenames, $methodCallRenames);
|
||||
}
|
||||
/**
|
||||
* @return MethodCallRenameInterface[]
|
||||
*/
|
||||
public function getMethodCallRenames() : array
|
||||
{
|
||||
return $this->methodCallRenames;
|
||||
}
|
||||
}
|
@ -62,7 +62,7 @@ final class RenameClassCallbackHandler extends NodeVisitorAbstract
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function handleClassLike(ClassLike $classLike) : array
|
||||
private function handleClassLike(ClassLike $classLike) : array
|
||||
{
|
||||
$oldToNewClasses = [];
|
||||
$className = $classLike->name;
|
||||
|
@ -18,7 +18,6 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\NodeManipulator\ClassManipulator;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\Renaming\Collector\MethodCallRenameCollector;
|
||||
use Rector\Renaming\Contract\MethodCallRenameInterface;
|
||||
use Rector\Renaming\ValueObject\MethodCallRename;
|
||||
use Rector\Renaming\ValueObject\MethodCallRenameWithArrayKey;
|
||||
@ -39,11 +38,6 @@ final class RenameMethodRector extends AbstractScopeAwareRector implements Confi
|
||||
* @var \Rector\Core\NodeManipulator\ClassManipulator
|
||||
*/
|
||||
private $classManipulator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Renaming\Collector\MethodCallRenameCollector
|
||||
*/
|
||||
private $methodCallRenameCollector;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Reflection\ReflectionResolver
|
||||
@ -54,10 +48,9 @@ final class RenameMethodRector extends AbstractScopeAwareRector implements Confi
|
||||
* @var \PHPStan\Reflection\ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
public function __construct(ClassManipulator $classManipulator, MethodCallRenameCollector $methodCallRenameCollector, ReflectionResolver $reflectionResolver, ReflectionProvider $reflectionProvider)
|
||||
public function __construct(ClassManipulator $classManipulator, ReflectionResolver $reflectionResolver, ReflectionProvider $reflectionProvider)
|
||||
{
|
||||
$this->classManipulator = $classManipulator;
|
||||
$this->methodCallRenameCollector = $methodCallRenameCollector;
|
||||
$this->reflectionResolver = $reflectionResolver;
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
}
|
||||
@ -114,7 +107,6 @@ CODE_SAMPLE
|
||||
{
|
||||
Assert::allIsAOf($configuration, MethodCallRenameInterface::class);
|
||||
$this->methodCallRenames = $configuration;
|
||||
$this->methodCallRenameCollector->addMethodCallRenames($configuration);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Stmt\ClassMethod $node
|
||||
|
@ -74,7 +74,7 @@ CODE_SAMPLE
|
||||
continue;
|
||||
}
|
||||
unset($node->args[0]);
|
||||
return new MethodCall($node, 'usePutenv');
|
||||
return new MethodCall($node, $newArgToMethodCall->getMethodCall());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ final class PhpDocNestedAnnotationGuard
|
||||
$parsedPhpDocText = (string) $phpDocInfo->getPhpDocNode();
|
||||
return !$this->hasAnnotationCountChanged($originalPhpDocText, $parsedPhpDocText);
|
||||
}
|
||||
public function hasAnnotationCountChanged(string $originalPhpDocText, string $updatedPhpDocText) : bool
|
||||
private function hasAnnotationCountChanged(string $originalPhpDocText, string $updatedPhpDocText) : bool
|
||||
{
|
||||
$originalAnnotationCount = \count(Strings::matchAll($originalPhpDocText, self::SIMPLE_ANNOTATION_REGEX));
|
||||
$reconstructedAnnotationCount = \count(Strings::matchAll($updatedPhpDocText, self::SIMPLE_ANNOTATION_REGEX));
|
||||
|
@ -48,21 +48,6 @@ final class CallerParamMatcher
|
||||
}
|
||||
return $callParam->type;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\FuncCall $call
|
||||
*/
|
||||
public function matchCallParam($call, Param $param, Scope $scope) : ?Param
|
||||
{
|
||||
$callArgPosition = $this->matchCallArgPosition($call, $param);
|
||||
if ($callArgPosition === null) {
|
||||
return null;
|
||||
}
|
||||
$classMethodOrFunction = $this->astResolver->resolveClassMethodOrFunctionFromCall($call, $scope);
|
||||
if ($classMethodOrFunction === null) {
|
||||
return null;
|
||||
}
|
||||
return $classMethodOrFunction->params[$callArgPosition] ?? null;
|
||||
}
|
||||
public function matchParentParam(StaticCall $parentStaticCall, Param $param, Scope $scope) : ?Param
|
||||
{
|
||||
$methodName = $this->nodeNameResolver->getName($parentStaticCall->name);
|
||||
@ -76,6 +61,21 @@ final class CallerParamMatcher
|
||||
}
|
||||
return $this->resolveParentMethodParam($scope, $methodName, $parentStaticCallArgPosition);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\FuncCall $call
|
||||
*/
|
||||
private function matchCallParam($call, Param $param, Scope $scope) : ?Param
|
||||
{
|
||||
$callArgPosition = $this->matchCallArgPosition($call, $param);
|
||||
if ($callArgPosition === null) {
|
||||
return null;
|
||||
}
|
||||
$classMethodOrFunction = $this->astResolver->resolveClassMethodOrFunctionFromCall($call, $scope);
|
||||
if ($classMethodOrFunction === null) {
|
||||
return null;
|
||||
}
|
||||
return $classMethodOrFunction->params[$callArgPosition] ?? null;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\FuncCall $call
|
||||
*/
|
||||
|
@ -142,6 +142,6 @@ final class StrictReturnNewAnalyzer
|
||||
if (!\is_string($variableName)) {
|
||||
return null;
|
||||
}
|
||||
return new AssignToVariable($assignedVar, $variableName, $assign->expr);
|
||||
return new AssignToVariable($variableName, $assign->expr);
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,11 @@ CODE_SAMPLE
|
||||
}
|
||||
return $this->decorateParamWithType($parentNode, $node);
|
||||
}
|
||||
public function decorateParamWithType(ClassMethod $classMethod, Param $param) : ?Param
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
return PhpVersionFeature::TYPED_PROPERTIES;
|
||||
}
|
||||
private function decorateParamWithType(ClassMethod $classMethod, Param $param) : ?Param
|
||||
{
|
||||
if ($param->type !== null) {
|
||||
return null;
|
||||
@ -121,10 +125,6 @@ CODE_SAMPLE
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
return PhpVersionFeature::TYPED_PROPERTIES;
|
||||
}
|
||||
/**
|
||||
* @return Identifier|Name|ComplexType|null
|
||||
*/
|
||||
|
@ -17,12 +17,13 @@ use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\Privatization\Guard\ParentPropertyLookupGuard;
|
||||
use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\GetterTypeDeclarationPropertyTypeInferer;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictGetterMethodReturnTypeRector\TypedPropertyFromStrictGetterMethodReturnTypeRectorTest
|
||||
*/
|
||||
final class TypedPropertyFromStrictGetterMethodReturnTypeRector extends AbstractRector
|
||||
final class TypedPropertyFromStrictGetterMethodReturnTypeRector extends AbstractRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -111,14 +111,11 @@ final class ReturnTypeInferer
|
||||
return new MixedType();
|
||||
}
|
||||
$type = $this->verifyThisType($type, $functionLike);
|
||||
if (!$type instanceof Type) {
|
||||
return new MixedType();
|
||||
}
|
||||
// normalize ConstStringType to ClassStringType
|
||||
$resolvedType = $this->genericClassStringTypeNormalizer->normalize($type);
|
||||
return $this->resolveTypeWithVoidHandling($functionLike, $resolvedType);
|
||||
}
|
||||
public function verifyStaticType(Type $type, bool $isSupportedStaticReturnType) : ?Type
|
||||
private function verifyStaticType(Type $type, bool $isSupportedStaticReturnType) : ?Type
|
||||
{
|
||||
if ($this->isStaticType($type)) {
|
||||
/** @var TypeWithClassName $type */
|
||||
@ -129,7 +126,7 @@ final class ReturnTypeInferer
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
public function verifyThisType(Type $type, FunctionLike $functionLike) : ?Type
|
||||
private function verifyThisType(Type $type, FunctionLike $functionLike) : Type
|
||||
{
|
||||
if (!$type instanceof ThisType) {
|
||||
return $type;
|
||||
|
@ -5,11 +5,8 @@ namespace Rector\TypeDeclaration;
|
||||
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\Constant\ConstantArrayType;
|
||||
use PHPStan\Type\Constant\ConstantStringType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\NeverType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\StringType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeTraverser;
|
||||
use PHPStan\Type\UnionType;
|
||||
@ -40,27 +37,6 @@ final class TypeNormalizer
|
||||
$this->typeFactory = $typeFactory;
|
||||
$this->privatesAccessor = $privatesAccessor;
|
||||
}
|
||||
public function convertConstantArrayTypeToArrayType(ConstantArrayType $constantArrayType) : ?ArrayType
|
||||
{
|
||||
$nonConstantValueTypes = [];
|
||||
if ($constantArrayType->getItemType() instanceof UnionType) {
|
||||
/** @var UnionType $unionType */
|
||||
$unionType = $constantArrayType->getItemType();
|
||||
foreach ($unionType->getTypes() as $unionedType) {
|
||||
if ($unionedType instanceof ConstantStringType) {
|
||||
$stringType = new StringType();
|
||||
$nonConstantValueTypes[\get_class($stringType)] = $stringType;
|
||||
} elseif ($unionedType instanceof ObjectType) {
|
||||
$nonConstantValueTypes[] = $unionedType;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return $this->createArrayTypeFromNonConstantValueTypes($nonConstantValueTypes);
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
*
|
||||
@ -150,19 +126,6 @@ final class TypeNormalizer
|
||||
{
|
||||
return $countTraversedTypes === 2 && ($this->isArrayNeverType($traversedTypeTypes[0]) || $this->isArrayNeverType($traversedTypeTypes[1]));
|
||||
}
|
||||
/**
|
||||
* @param array<string|int, Type> $nonConstantValueTypes
|
||||
*/
|
||||
private function createArrayTypeFromNonConstantValueTypes(array $nonConstantValueTypes) : ArrayType
|
||||
{
|
||||
$nonConstantValueTypes = \array_values($nonConstantValueTypes);
|
||||
if (\count($nonConstantValueTypes) > 1) {
|
||||
$nonConstantValueType = new UnionType($nonConstantValueTypes);
|
||||
} else {
|
||||
$nonConstantValueType = $nonConstantValueTypes[0];
|
||||
}
|
||||
return new ArrayType(new MixedType(), $nonConstantValueType);
|
||||
}
|
||||
private function collectNestedArrayTypeFromUnionType(UnionType $unionType, int $arrayNesting) : void
|
||||
{
|
||||
foreach ($unionType->getTypes() as $unionedType) {
|
||||
|
@ -6,6 +6,9 @@ namespace Rector\TypeDeclaration\ValueObject;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Core\Validation\RectorAssert;
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
final class AddReturnTypeDeclaration
|
||||
{
|
||||
/**
|
||||
|
@ -4,14 +4,8 @@ declare (strict_types=1);
|
||||
namespace Rector\TypeDeclaration\ValueObject;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
final class AssignToVariable
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \PhpParser\Node\Expr\Variable
|
||||
*/
|
||||
private $variable;
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
@ -22,16 +16,11 @@ final class AssignToVariable
|
||||
* @var \PhpParser\Node\Expr
|
||||
*/
|
||||
private $assignedExpr;
|
||||
public function __construct(Variable $variable, string $variableName, Expr $assignedExpr)
|
||||
public function __construct(string $variableName, Expr $assignedExpr)
|
||||
{
|
||||
$this->variable = $variable;
|
||||
$this->variableName = $variableName;
|
||||
$this->assignedExpr = $assignedExpr;
|
||||
}
|
||||
public function getVariable() : Variable
|
||||
{
|
||||
return $this->variable;
|
||||
}
|
||||
public function getVariableName() : string
|
||||
{
|
||||
return $this->variableName;
|
||||
|
@ -138,7 +138,7 @@ final class ApplicationFileProcessor
|
||||
return $systemErrorsAndFileDiffs;
|
||||
}
|
||||
/**
|
||||
* @internal Use only for tests
|
||||
* @api use only for tests
|
||||
*
|
||||
* @param File[] $files
|
||||
* @return array{system_errors: SystemError[], file_diffs: FileDiff[]}
|
||||
|
@ -87,7 +87,7 @@ final class RemovedAndAddedFilesCollector
|
||||
return \count($this->removedFilePaths);
|
||||
}
|
||||
/**
|
||||
* For testing
|
||||
* @api For testing
|
||||
*/
|
||||
public function reset() : void
|
||||
{
|
||||
|
@ -6,6 +6,8 @@ namespace Rector\Core\Application;
|
||||
use DateTime;
|
||||
use Rector\Core\Exception\VersionException;
|
||||
/**
|
||||
* @api
|
||||
*
|
||||
* Inspired by https://github.com/composer/composer/blob/master/src/Composer/Composer.php
|
||||
* See https://github.com/composer/composer/blob/6587715d0f8cae0cd39073b3bc5f018d0e6b84fe/src/Composer/Compiler.php#L208
|
||||
*
|
||||
@ -17,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '88629427917b7d359beeb1a0b34d39d2127472b9';
|
||||
public const PACKAGE_VERSION = 'bfa1891c50677b01136a9308fd3c3ecc12e267d9';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-12-23 09:40:11';
|
||||
public const RELEASE_DATE = '2022-12-23 18:06:25';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -8,6 +8,7 @@ use ReflectionClass;
|
||||
final class ExtensionConfigResolver
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
* @return string[]
|
||||
*/
|
||||
public function provide() : array
|
||||
|
@ -26,6 +26,7 @@ final class ConfigurationFactory
|
||||
$this->rectorOutputStyle = $rectorOutputStyle;
|
||||
}
|
||||
/**
|
||||
* @api used in tests
|
||||
* @param string[] $paths
|
||||
*/
|
||||
public function createForTests(array $paths) : Configuration
|
||||
|
@ -23,10 +23,16 @@ final class RectorConfigProvider
|
||||
{
|
||||
return $this->parameterProvider->provideBoolParameter(\Rector\Core\Configuration\Option::AUTO_IMPORT_NAMES);
|
||||
}
|
||||
/**
|
||||
* @api symfony
|
||||
*/
|
||||
public function getSymfonyContainerPhp() : string
|
||||
{
|
||||
return $this->parameterProvider->provideStringParameter(\Rector\Core\Configuration\Option::SYMFONY_CONTAINER_PHP_PATH_PARAMETER);
|
||||
}
|
||||
/**
|
||||
* @api symfony
|
||||
*/
|
||||
public function getSymfonyContainerXml() : string
|
||||
{
|
||||
return $this->parameterProvider->provideStringParameter(\Rector\Core\Configuration\Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER);
|
||||
|
@ -24,7 +24,7 @@ final class ValueObjectInliner
|
||||
* @param ReflectionClass<object> $reflectionClass
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function resolveArgumentValues(ReflectionClass $reflectionClass, object $object) : array
|
||||
private static function resolveArgumentValues(ReflectionClass $reflectionClass, object $object) : array
|
||||
{
|
||||
$argumentValues = [];
|
||||
$constructorReflectionMethod = $reflectionClass->getConstructor();
|
||||
|
@ -25,18 +25,12 @@ final class OutputFormatterCollector
|
||||
$this->ensureOutputFormatExists($name);
|
||||
return $this->outputFormatters[$name];
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNames() : array
|
||||
{
|
||||
return \array_keys($this->outputFormatters);
|
||||
}
|
||||
private function ensureOutputFormatExists(string $name) : void
|
||||
{
|
||||
if (isset($this->outputFormatters[$name])) {
|
||||
return;
|
||||
}
|
||||
throw new InvalidConfigurationException(\sprintf('Output formatter "%s" was not found. Pick one of "%s".', $name, \implode('", "', $this->getNames())));
|
||||
$outputFormatterNames = \array_keys($this->outputFormatters);
|
||||
throw new InvalidConfigurationException(\sprintf('Output formatter "%s" was not found. Pick one of "%s".', $name, \implode('", "', $outputFormatterNames)));
|
||||
}
|
||||
}
|
||||
|
@ -4,25 +4,8 @@ declare (strict_types=1);
|
||||
namespace Rector\Core\Error;
|
||||
|
||||
use PHPStan\AnalysedCodeException;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Throwable;
|
||||
final class ExceptionCorrector
|
||||
{
|
||||
public function matchRectorClass(Throwable $throwable) : ?string
|
||||
{
|
||||
if (!isset($throwable->getTrace()[0])) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($throwable->getTrace()[0]['class'])) {
|
||||
return null;
|
||||
}
|
||||
/** @var string $class */
|
||||
$class = $throwable->getTrace()[0]['class'];
|
||||
if (!\is_a($class, RectorInterface::class, \true)) {
|
||||
return null;
|
||||
}
|
||||
return $class;
|
||||
}
|
||||
public function getAutoloadExceptionMessageAndAddLocation(AnalysedCodeException $analysedCodeException) : string
|
||||
{
|
||||
return \sprintf('Analyze error: "%s". Include your files in "$rectorConfig->autoloadPaths([...]);" or "$rectorConfig->bootstrapFiles([...]);" in "rector.php" config.%sSee https://github.com/rectorphp/rector#configuration', $analysedCodeException->getMessage(), \PHP_EOL);
|
||||
|
@ -29,6 +29,9 @@ final class RectorKernel
|
||||
{
|
||||
$this->configureCallValuesCollector = new ConfigureCallValuesCollector();
|
||||
}
|
||||
/**
|
||||
* @api used in tests
|
||||
*/
|
||||
public function create() : ContainerInterface
|
||||
{
|
||||
return $this->createFromConfigs([]);
|
||||
@ -52,6 +55,9 @@ final class RectorKernel
|
||||
$this->container = $containerBuilder;
|
||||
return $containerBuilder;
|
||||
}
|
||||
/**
|
||||
* @api used in tests
|
||||
*/
|
||||
public function getContainer() : ContainerInterface
|
||||
{
|
||||
if ($this->container === null) {
|
||||
|
@ -15,6 +15,9 @@ final class CoalesceAnalyzer
|
||||
* @var array<class-string<Expr>>
|
||||
*/
|
||||
private const ISSETABLE_EXPR = [Variable::class, ArrayDimFetch::class, PropertyFetch::class, StaticPropertyFetch::class];
|
||||
/**
|
||||
* @api downgrade
|
||||
*/
|
||||
public function hasIssetableLeft(Coalesce $coalesce) : bool
|
||||
{
|
||||
$leftClass = \get_class($coalesce->left);
|
||||
|
@ -9,6 +9,7 @@ use PhpParser\NodeVisitor\NameResolver;
|
||||
final class NamespacedNameDecorator
|
||||
{
|
||||
/**
|
||||
* @api downgrade
|
||||
* @param \PhpParser\Node|mixed[] $node
|
||||
*/
|
||||
public function decorate($node) : void
|
||||
|
@ -48,6 +48,9 @@ final class ArrayManipulator
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* @api symfony
|
||||
*/
|
||||
public function addItemToArrayUnderKey(Array_ $array, ArrayItem $newArrayItem, string $key) : void
|
||||
{
|
||||
foreach ($array->items as $item) {
|
||||
@ -64,6 +67,9 @@ final class ArrayManipulator
|
||||
}
|
||||
$array->items[] = new ArrayItem(new Array_([$newArrayItem]), new String_($key));
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public function findItemInInArrayByKeyAndUnset(Array_ $array, string $keyName) : ?ArrayItem
|
||||
{
|
||||
foreach ($array->items as $i => $item) {
|
||||
@ -84,6 +90,9 @@ final class ArrayManipulator
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @api symfony
|
||||
*/
|
||||
public function hasKeyName(ArrayItem $arrayItem, string $name) : bool
|
||||
{
|
||||
if (!$arrayItem->key instanceof String_) {
|
||||
|
@ -118,6 +118,7 @@ final class AssignManipulator
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* @api doctrine
|
||||
* @return array<PropertyFetch|StaticPropertyFetch>
|
||||
*/
|
||||
public function resolveAssignsToLocalPropertyFetches(FunctionLike $functionLike) : array
|
||||
|
@ -113,6 +113,9 @@ final class ClassDependencyManipulator
|
||||
$this->addConstructorDependencyWithCustomAssign($class, $propertyMetadata->getName(), $propertyMetadata->getType(), $assign);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @api doctrine
|
||||
*/
|
||||
public function addConstructorDependencyWithCustomAssign(Class_ $class, string $name, ?Type $type, Assign $assign) : void
|
||||
{
|
||||
/** @var ClassMethod|null $constructorMethod */
|
||||
@ -129,6 +132,7 @@ final class ClassDependencyManipulator
|
||||
$this->dependencyClassMethodDecorator->decorateConstructorWithParentDependencies($class, $constructorMethod, $scope);
|
||||
}
|
||||
/**
|
||||
* @api doctrine
|
||||
* @param Stmt[] $stmts
|
||||
*/
|
||||
public function addStmtsToConstructorIfNotThereYet(Class_ $class, array $stmts) : void
|
||||
|
@ -57,6 +57,7 @@ final class ClassInsertManipulator
|
||||
$this->addAsFirstMethod($class, $classConst);
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
* @param Property[] $properties
|
||||
*/
|
||||
public function addPropertiesToClass(Class_ $class, array $properties) : void
|
||||
|
@ -3,7 +3,6 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\NodeManipulator;
|
||||
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\ObjectType;
|
||||
@ -50,6 +49,9 @@ final class ClassManipulator
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* @api phpunit
|
||||
*/
|
||||
public function hasTrait(Class_ $class, string $desiredTrait) : bool
|
||||
{
|
||||
foreach ($class->getTraitUses() as $traitUse) {
|
||||
@ -62,16 +64,4 @@ final class ClassManipulator
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
public function replaceTrait(Class_ $class, string $oldTrait, string $newTrait) : void
|
||||
{
|
||||
foreach ($class->getTraitUses() as $traitUse) {
|
||||
foreach ($traitUse->traits as $key => $traitTrait) {
|
||||
if (!$this->nodeNameResolver->isName($traitTrait, $oldTrait)) {
|
||||
continue;
|
||||
}
|
||||
$traitUse->traits[$key] = new FullyQualified($newTrait);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,20 +3,13 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\NodeManipulator;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
final class ClassMethodManipulator
|
||||
{
|
||||
/**
|
||||
@ -29,21 +22,15 @@ final class ClassMethodManipulator
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeTypeResolver\NodeTypeResolver
|
||||
*/
|
||||
private $nodeTypeResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Reflection\ReflectionResolver
|
||||
*/
|
||||
private $reflectionResolver;
|
||||
public function __construct(BetterNodeFinder $betterNodeFinder, NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, ReflectionResolver $reflectionResolver)
|
||||
public function __construct(BetterNodeFinder $betterNodeFinder, NodeNameResolver $nodeNameResolver, ReflectionResolver $reflectionResolver)
|
||||
{
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
$this->reflectionResolver = $reflectionResolver;
|
||||
}
|
||||
public function isNamedConstructor(ClassMethod $classMethod) : bool
|
||||
@ -85,39 +72,4 @@ final class ClassMethodManipulator
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* @param string[] $possibleNames
|
||||
*/
|
||||
public function addMethodParameterIfMissing(Node $node, ObjectType $objectType, array $possibleNames) : string
|
||||
{
|
||||
$classMethod = $this->betterNodeFinder->findParentType($node, ClassMethod::class);
|
||||
if (!$classMethod instanceof ClassMethod) {
|
||||
// or null?
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
foreach ($classMethod->params as $paramNode) {
|
||||
if (!$this->nodeTypeResolver->isObjectType($paramNode, $objectType)) {
|
||||
continue;
|
||||
}
|
||||
return $this->nodeNameResolver->getName($paramNode);
|
||||
}
|
||||
$paramName = $this->resolveName($classMethod, $possibleNames);
|
||||
$classMethod->params[] = new Param(new Variable($paramName), null, new FullyQualified($objectType->getClassName()));
|
||||
return $paramName;
|
||||
}
|
||||
/**
|
||||
* @param string[] $possibleNames
|
||||
*/
|
||||
private function resolveName(ClassMethod $classMethod, array $possibleNames) : string
|
||||
{
|
||||
foreach ($possibleNames as $possibleName) {
|
||||
foreach ($classMethod->params as $paramNode) {
|
||||
if ($this->nodeNameResolver->isName($paramNode, $possibleName)) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
return $possibleName;
|
||||
}
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\BinaryOp\Identical;
|
||||
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
|
||||
use PhpParser\Node\Expr\Exit_;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Foreach_;
|
||||
@ -19,7 +18,6 @@ use Rector\Core\PhpParser\Comparing\NodeComparator;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\PhpParser\Node\Value\ValueResolver;
|
||||
use Rector\EarlyReturn\NodeTransformer\ConditionInverter;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
final class IfManipulator
|
||||
{
|
||||
/**
|
||||
@ -27,11 +25,6 @@ final class IfManipulator
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeManipulator\StmtsManipulator
|
||||
@ -52,10 +45,9 @@ final class IfManipulator
|
||||
* @var \Rector\Core\PhpParser\Comparing\NodeComparator
|
||||
*/
|
||||
private $nodeComparator;
|
||||
public function __construct(BetterNodeFinder $betterNodeFinder, NodeNameResolver $nodeNameResolver, \Rector\Core\NodeManipulator\StmtsManipulator $stmtsManipulator, ValueResolver $valueResolver, ConditionInverter $conditionInverter, NodeComparator $nodeComparator)
|
||||
public function __construct(BetterNodeFinder $betterNodeFinder, \Rector\Core\NodeManipulator\StmtsManipulator $stmtsManipulator, ValueResolver $valueResolver, ConditionInverter $conditionInverter, NodeComparator $nodeComparator)
|
||||
{
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->stmtsManipulator = $stmtsManipulator;
|
||||
$this->valueResolver = $valueResolver;
|
||||
$this->conditionInverter = $conditionInverter;
|
||||
@ -159,22 +151,6 @@ final class IfManipulator
|
||||
}
|
||||
return $this->nodeComparator->areNodesEqual($desiredExpr, $lastElseStmt->var);
|
||||
}
|
||||
/**
|
||||
* Matches:
|
||||
* if (<some_function>) {
|
||||
* } else {
|
||||
* }
|
||||
*/
|
||||
public function isIfOrIfElseWithFunctionCondition(If_ $if, string $functionName) : bool
|
||||
{
|
||||
if ((bool) $if->elseifs) {
|
||||
return \false;
|
||||
}
|
||||
if (!$if->cond instanceof FuncCall) {
|
||||
return \false;
|
||||
}
|
||||
return $this->nodeNameResolver->isName($if->cond, $functionName);
|
||||
}
|
||||
/**
|
||||
* @return If_[]
|
||||
*/
|
||||
|
@ -34,6 +34,7 @@ final class MethodCallManipulator
|
||||
$this->fluentChainMethodCallNodeAnalyzer = $fluentChainMethodCallNodeAnalyzer;
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
* @return string[]
|
||||
*/
|
||||
public function findMethodCallNamesOnVariable(Variable $variable) : array
|
||||
@ -52,7 +53,7 @@ final class MethodCallManipulator
|
||||
/**
|
||||
* @return MethodCall[]
|
||||
*/
|
||||
public function findMethodCallsOnVariable(Variable $variable) : array
|
||||
private function findMethodCallsOnVariable(Variable $variable) : array
|
||||
{
|
||||
// get scope node, e.g. parent function call, method call or anonymous function
|
||||
$classMethod = $this->betterNodeFinder->findParentType($variable, ClassMethod::class);
|
||||
|
@ -152,16 +152,6 @@ final class PropertyManipulator
|
||||
$this->propertyFetchAnalyzer = $propertyFetchAnalyzer;
|
||||
$this->multiInstanceofChecker = $multiInstanceofChecker;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $propertyOrPromotedParam
|
||||
*/
|
||||
public function isAllowedReadOnly($propertyOrPromotedParam, PhpDocInfo $phpDocInfo) : bool
|
||||
{
|
||||
if ($phpDocInfo->hasByAnnotationClasses(self::ALLOWED_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES)) {
|
||||
return \true;
|
||||
}
|
||||
return $this->phpAttributeAnalyzer->hasPhpAttributes($propertyOrPromotedParam, self::ALLOWED_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $propertyOrPromotedParam
|
||||
*/
|
||||
@ -275,6 +265,16 @@ final class PropertyManipulator
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $propertyOrPromotedParam
|
||||
*/
|
||||
private function isAllowedReadOnly($propertyOrPromotedParam, PhpDocInfo $phpDocInfo) : bool
|
||||
{
|
||||
if ($phpDocInfo->hasByAnnotationClasses(self::ALLOWED_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES)) {
|
||||
return \true;
|
||||
}
|
||||
return $this->phpAttributeAnalyzer->hasPhpAttributes($propertyOrPromotedParam, self::ALLOWED_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES);
|
||||
}
|
||||
private function isPropertyAssignedOnlyInConstructor(Class_ $class, string $propertyName, ?ClassMethod $classMethod) : bool
|
||||
{
|
||||
if (!$classMethod instanceof ClassMethod) {
|
||||
|
@ -5,11 +5,6 @@ namespace Rector\Core\Php;
|
||||
|
||||
final class ReservedKeywordAnalyzer
|
||||
{
|
||||
/**
|
||||
* @see https://www.php.net/manual/en/reserved.keywords.php
|
||||
* @var string[]
|
||||
*/
|
||||
private const RESERVED_KEYWORDS = ['__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'finally', 'fn', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'match', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'readonly', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor', 'yield', 'yield from'];
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
@ -18,9 +13,4 @@ final class ReservedKeywordAnalyzer
|
||||
{
|
||||
return \in_array($name, self::NATIVE_VARIABLE_NAMES, \true);
|
||||
}
|
||||
public function isReserved(string $keyword) : bool
|
||||
{
|
||||
$keyword = \strtolower($keyword);
|
||||
return \in_array($keyword, self::RESERVED_KEYWORDS, \true);
|
||||
}
|
||||
}
|
||||
|
@ -116,13 +116,6 @@ final class AstResolver
|
||||
$classReflection = $this->reflectionProvider->getClass($className);
|
||||
return $this->resolveClassFromClassReflection($classReflection);
|
||||
}
|
||||
/**
|
||||
* @return \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Trait_|\PhpParser\Node\Stmt\Interface_|\PhpParser\Node\Stmt\Enum_|null
|
||||
*/
|
||||
public function resolveClassFromObjectType(TypeWithClassName $typeWithClassName)
|
||||
{
|
||||
return $this->resolveClassFromName($typeWithClassName->getClassName());
|
||||
}
|
||||
public function resolveClassMethodFromMethodReflection(MethodReflection $methodReflection) : ?ClassMethod
|
||||
{
|
||||
$classReflection = $methodReflection->getDeclaringClass();
|
||||
|
@ -212,6 +212,7 @@ final class BetterNodeFinder
|
||||
return $this->nodeFinder->find($nodes, $filter);
|
||||
}
|
||||
/**
|
||||
* @api symfony
|
||||
* @param Node[] $nodes
|
||||
* @return ClassLike|null
|
||||
*/
|
||||
@ -254,6 +255,7 @@ final class BetterNodeFinder
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @api symfony
|
||||
* @return Assign|null
|
||||
*/
|
||||
public function findPreviousAssignToExpr(Expr $expr) : ?Node
|
||||
|
@ -25,6 +25,9 @@ final class NamedVariableFactory
|
||||
$this->variableNaming = $variableNaming;
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
}
|
||||
/**
|
||||
* @api downgrade
|
||||
*/
|
||||
public function createVariable(Node $node, string $variableName) : Variable
|
||||
{
|
||||
$currentStmt = $this->betterNodeFinder->resolveCurrentStatement($node);
|
||||
|
@ -35,8 +35,6 @@ use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
use PhpParser\Node\Stmt\UseUse;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\Type\Type;
|
||||
@ -93,15 +91,6 @@ final class NodeFactory
|
||||
$this->currentNodeProvider = $currentNodeProvider;
|
||||
$this->propertyTypeDecorator = $propertyTypeDecorator;
|
||||
}
|
||||
/**
|
||||
* Creates "SomeClass::CONSTANT"
|
||||
* @deprecated
|
||||
*/
|
||||
public function createShortClassConstFetch(string $shortClassName, string $constantName) : ClassConstFetch
|
||||
{
|
||||
$name = new Name($shortClassName);
|
||||
return $this->createClassConstFetchFromName($name, $constantName);
|
||||
}
|
||||
/**
|
||||
* @param string|ObjectReference::* $className
|
||||
* Creates "\SomeClass::CONSTANT"
|
||||
@ -205,6 +194,7 @@ final class NodeFactory
|
||||
return $property;
|
||||
}
|
||||
/**
|
||||
* @api symfony
|
||||
* @param mixed[] $arguments
|
||||
*/
|
||||
public function createLocalMethodCall(string $method, array $arguments = []) : MethodCall
|
||||
@ -236,6 +226,9 @@ final class NodeFactory
|
||||
{
|
||||
return new StaticCall(new Name(ObjectReference::PARENT), new Identifier(MethodName::CONSTRUCT), $this->createArgsFromParams($params));
|
||||
}
|
||||
/**
|
||||
* @api doctrine
|
||||
*/
|
||||
public function createPrivateProperty(string $name) : Property
|
||||
{
|
||||
$propertyBuilder = new PropertyBuilder($name);
|
||||
@ -261,19 +254,6 @@ final class NodeFactory
|
||||
}
|
||||
return $previousConcat;
|
||||
}
|
||||
/**
|
||||
* @param string[] $names
|
||||
* @return Use_[]
|
||||
*/
|
||||
public function createUsesFromNames(array $names) : array
|
||||
{
|
||||
$uses = [];
|
||||
foreach ($names as $name) {
|
||||
$useUse = new UseUse(new Name($name));
|
||||
$uses[] = new Use_([$useUse]);
|
||||
}
|
||||
return $uses;
|
||||
}
|
||||
/**
|
||||
* @param string|ObjectReference::* $class
|
||||
* @param Node[] $args
|
||||
@ -337,6 +317,7 @@ final class NodeFactory
|
||||
return new ConstFetch(new Name('true'));
|
||||
}
|
||||
/**
|
||||
* @api phpunit
|
||||
* @param string|ObjectReference::* $constantName
|
||||
*/
|
||||
public function createClassConstFetchFromName(Name $className, string $constantName) : ClassConstFetch
|
||||
|
@ -120,6 +120,7 @@ final class ValueResolver
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @api downgrade symfony
|
||||
* @param mixed[] $expectedValues
|
||||
*/
|
||||
public function isValues(Expr $expr, array $expectedValues) : bool
|
||||
|
@ -25,6 +25,8 @@ final class NodeTransformer
|
||||
*/
|
||||
private const PERCENT_TEXT_REGEX = '#^%\\w$#';
|
||||
/**
|
||||
* @api symfony
|
||||
*
|
||||
* From:
|
||||
* - sprintf("Hi %s", $name);
|
||||
*
|
||||
@ -71,6 +73,9 @@ final class NodeTransformer
|
||||
}
|
||||
return $yieldNodes;
|
||||
}
|
||||
/**
|
||||
* @api symfony
|
||||
*/
|
||||
public function transformConcatToStringArray(Concat $concat) : Array_
|
||||
{
|
||||
$arrayItems = $this->transformConcatToItems($concat);
|
||||
|
@ -22,6 +22,7 @@ final class SimplePhpParser
|
||||
$this->phpParser = $parserFactory->create(ParserFactory::PREFER_PHP7);
|
||||
}
|
||||
/**
|
||||
* @api tests
|
||||
* @return Stmt[]
|
||||
*/
|
||||
public function parseFile(string $filePath) : array
|
||||
|
@ -133,6 +133,9 @@ final class BetterStandardPrinter extends Standard implements NodePrinterInterfa
|
||||
$stmts = \array_values($stmts);
|
||||
return parent::prettyPrintFile($stmts) . \PHP_EOL;
|
||||
}
|
||||
/**
|
||||
* @api magic method in parent
|
||||
*/
|
||||
public function pFileWithoutNamespace(FileWithoutNamespace $fileWithoutNamespace) : string
|
||||
{
|
||||
$content = $this->pStmts($fileWithoutNamespace->stmts, \false);
|
||||
|
@ -30,6 +30,8 @@ final class FormatPerservingPrinter
|
||||
$this->filesystem = $filesystem;
|
||||
}
|
||||
/**
|
||||
* @api tests
|
||||
*
|
||||
* @param Node[] $newStmts
|
||||
* @param Node[] $oldStmts
|
||||
* @param Node[] $oldTokens
|
||||
|
@ -30,20 +30,9 @@ final class MissingRectorRulesReporter
|
||||
}
|
||||
public function reportIfMissing() : ?int
|
||||
{
|
||||
$activeRectors = \array_filter($this->rectors, static function (RectorInterface $rector) : bool {
|
||||
if ($rector instanceof PostRectorInterface) {
|
||||
return \false;
|
||||
}
|
||||
return !$rector instanceof ComplementaryRectorInterface;
|
||||
});
|
||||
if ($activeRectors !== []) {
|
||||
if ($this->filterActiveRectors($this->rectors) !== []) {
|
||||
return null;
|
||||
}
|
||||
$this->report();
|
||||
return Command::FAILURE;
|
||||
}
|
||||
public function report() : void
|
||||
{
|
||||
$this->rectorOutputStyle->warning('We could not find any Rector rules to run. You have 2 options to add them:');
|
||||
$this->rectorOutputStyle->title('1. Add single rule to "rector.php"');
|
||||
$this->rectorOutputStyle->writeln(' $rectorConfig->rule(...);');
|
||||
@ -54,5 +43,19 @@ final class MissingRectorRulesReporter
|
||||
$this->rectorOutputStyle->title('Missing "rector.php" in your project? Let Rector create it for you');
|
||||
$this->rectorOutputStyle->writeln(' vendor/bin/rector init');
|
||||
$this->rectorOutputStyle->newLine();
|
||||
return Command::FAILURE;
|
||||
}
|
||||
/**
|
||||
* @param RectorInterface[] $rectors
|
||||
* @return RectorInterface[]
|
||||
*/
|
||||
private function filterActiveRectors(array $rectors) : array
|
||||
{
|
||||
return \array_filter($rectors, static function (RectorInterface $rector) : bool {
|
||||
if ($rector instanceof PostRectorInterface) {
|
||||
return \false;
|
||||
}
|
||||
return !$rector instanceof ComplementaryRectorInterface;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -29,29 +29,6 @@ final class ArrayParametersMerger
|
||||
}
|
||||
return $right;
|
||||
}
|
||||
/**
|
||||
* The same as above, just with the case if both values being non-array, it will combined them to array:
|
||||
*
|
||||
* $this->mergeWithCombine(1, 2); // [1, 2]
|
||||
* @param mixed $left
|
||||
* @param mixed $right
|
||||
* @return mixed
|
||||
*/
|
||||
public function mergeWithCombine($left, $right)
|
||||
{
|
||||
if (\is_array($left) && \is_array($right)) {
|
||||
return $this->mergeLeftToRightWithCallable($left, $right, function ($leftValue, $rightValue) {
|
||||
return $this->mergeWithCombine($leftValue, $rightValue);
|
||||
});
|
||||
}
|
||||
if ($left === null && \is_array($right)) {
|
||||
return $right;
|
||||
}
|
||||
if (!empty($right) && (array) $left !== (array) $right) {
|
||||
return $this->mergeWithCombine((array) $right, (array) $left);
|
||||
}
|
||||
return $left;
|
||||
}
|
||||
/**
|
||||
* @param array<int|string, mixed> $left
|
||||
* @param array<int|string, mixed> $right
|
||||
|
@ -25,23 +25,8 @@ final class PrivatesAccessor
|
||||
$reflectionClass = new ReflectionClass($object);
|
||||
$object = $reflectionClass->newInstanceWithoutConstructor();
|
||||
}
|
||||
$methodReflection = $this->createAccessibleMethodReflection($object, $methodName);
|
||||
return $methodReflection->invokeArgs($object, $arguments);
|
||||
}
|
||||
/**
|
||||
* @param object|class-string $object
|
||||
* @param mixed $argument
|
||||
* @return mixed
|
||||
*/
|
||||
public function callPrivateMethodWithReference($object, string $methodName, $argument)
|
||||
{
|
||||
if (\is_string($object)) {
|
||||
$reflectionClass = new ReflectionClass($object);
|
||||
$object = $reflectionClass->newInstanceWithoutConstructor();
|
||||
}
|
||||
$methodReflection = $this->createAccessibleMethodReflection($object, $methodName);
|
||||
$methodReflection->invokeArgs($object, [&$argument]);
|
||||
return $argument;
|
||||
$reflectionMethod = $this->createAccessibleMethodReflection($object, $methodName);
|
||||
return $reflectionMethod->invokeArgs($object, $arguments);
|
||||
}
|
||||
/**
|
||||
* @template T of object
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user