mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Static fixes 3 (#4930)
* cleanpu baseline * static fixes * staitc fixes * [Naming] Remove dead classes UnderscoreCamelCaseParamRenamer and MatchTypeParamRenamer * static fixes * value object fixes * [ci-review] Rector Rectify Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
parent
d1e48f462a
commit
a759f1ffbc
@ -29,16 +29,12 @@ final class AnnotationItemsResolver
|
||||
return $annotationOrItems;
|
||||
}
|
||||
|
||||
if (is_object($annotationOrItems)) {
|
||||
// special case for private property annotations
|
||||
if ($this->annotationVisibilityDetector->isPrivate($annotationOrItems)) {
|
||||
return $this->resolvePrivatePropertyValues($annotationOrItems);
|
||||
}
|
||||
|
||||
return get_object_vars($annotationOrItems);
|
||||
// special case for private property annotations
|
||||
if ($this->annotationVisibilityDetector->isPrivate($annotationOrItems)) {
|
||||
return $this->resolvePrivatePropertyValues($annotationOrItems);
|
||||
}
|
||||
|
||||
return [];
|
||||
return get_object_vars($annotationOrItems);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,7 +158,7 @@ final class PhpDocInfo
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PhpDocTagNode[]|AttributeAwareNodeInterface[]
|
||||
* @return PhpDocTagNode[]&AttributeAwareNodeInterface[]
|
||||
*/
|
||||
public function getTagsByName(string $name): array
|
||||
{
|
||||
|
@ -116,7 +116,7 @@ final class ChangedFilesDetector
|
||||
|
||||
private function hashFile(SmartFileInfo $smartFileInfo): string
|
||||
{
|
||||
return hash_file('sha1', $smartFileInfo->getRealPath());
|
||||
return (string) sha1_file($smartFileInfo->getRealPath());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ use PHPStan\Analyser\MutatingScope;
|
||||
use PHPStan\Analyser\NodeScopeResolver;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Node\UnreachableStatementNode;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\Caching\Detector\ChangedFilesDetector;
|
||||
use Rector\Caching\FileSystem\DependencyResolver;
|
||||
@ -134,6 +135,7 @@ final class PHPStanNodeScopeResolver
|
||||
|
||||
// traversing trait inside class that is using it scope (from referenced) - the trait traversed by Rector is different (directly from parsed file)
|
||||
if ($scope->isInTrait()) {
|
||||
/** @var ClassReflection $classReflection */
|
||||
$classReflection = $scope->getTraitReflection();
|
||||
$traitName = $classReflection->getName();
|
||||
$this->traitNodeScopeCollector->addForTraitAndNode($traitName, $node, $scope);
|
||||
|
@ -73,15 +73,15 @@ final class PhpDocTypeRenamer
|
||||
}
|
||||
|
||||
private function shouldSkip(
|
||||
PhpDocParserNode $phpDocParserNode,
|
||||
TypeNode $typeNode,
|
||||
Node $phpParserNode,
|
||||
PseudoNamespaceToNamespace $pseudoNamespaceToNamespace
|
||||
): bool {
|
||||
if (! $phpDocParserNode instanceof IdentifierTypeNode) {
|
||||
if (! $typeNode instanceof IdentifierTypeNode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$staticType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($phpDocParserNode, $phpParserNode);
|
||||
$staticType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($typeNode, $phpParserNode);
|
||||
if (! $staticType instanceof ObjectType) {
|
||||
return true;
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ declare(strict_types=1);
|
||||
namespace Rector\PostRector\Rector\AbstractRector;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
@ -94,9 +94,6 @@ trait NodeCommandersTrait
|
||||
$this->nodeRemover = $nodeRemover;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FullyQualifiedObjectType|AliasedObjectType $objectType
|
||||
*/
|
||||
protected function addUseType(ObjectType $objectType, Node $positionNode): void
|
||||
{
|
||||
assert($objectType instanceof FullyQualifiedObjectType || $objectType instanceof AliasedObjectType);
|
||||
@ -187,11 +184,11 @@ trait NodeCommandersTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassLike|FunctionLike $nodeWithStatements
|
||||
* @param Class_|ClassMethod|Function_ $nodeWithStatements
|
||||
*/
|
||||
protected function removeNodeFromStatements(Node $nodeWithStatements, Node $nodeToRemove): void
|
||||
{
|
||||
foreach ($nodeWithStatements->stmts as $key => $stmt) {
|
||||
foreach ((array) $nodeWithStatements->stmts as $key => $stmt) {
|
||||
if ($nodeToRemove !== $stmt) {
|
||||
continue;
|
||||
}
|
||||
|
@ -61,6 +61,10 @@ CODE_SAMPLE
|
||||
|
||||
// special case for fluent methods
|
||||
foreach ($this->nodesToRemoveCollector->getNodesToRemove() as $key => $nodeToRemove) {
|
||||
if (! $node instanceof MethodCall) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $nodeToRemove instanceof MethodCall) {
|
||||
continue;
|
||||
}
|
||||
@ -109,21 +113,19 @@ CODE_SAMPLE
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function isChainMethodCallNodeToBeRemoved(Node $node, Node $nodeToRemove): bool
|
||||
{
|
||||
if (! $nodeToRemove instanceof MethodCall) {
|
||||
private function isChainMethodCallNodeToBeRemoved(
|
||||
MethodCall $mainMethodCall,
|
||||
MethodCall $toBeRemovedMethodCall
|
||||
): bool {
|
||||
if (! $mainMethodCall instanceof MethodCall || ! $mainMethodCall->var instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $node instanceof MethodCall || ! $node->var instanceof MethodCall) {
|
||||
if ($toBeRemovedMethodCall !== $mainMethodCall->var) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($nodeToRemove !== $node->var) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$methodName = $this->getName($node->name);
|
||||
$methodName = $this->getName($mainMethodCall->name);
|
||||
|
||||
return $methodName !== null;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ namespace Rector\StaticTypeMapper\PhpParser;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
|
||||
use Rector\StaticTypeMapper\Mapper\ScalarStringToTypeMapper;
|
||||
@ -33,11 +32,6 @@ final class IdentifierNodeMapper implements PhpParserNodeMapperInterface
|
||||
*/
|
||||
public function mapToPHPStan(Node $node): Type
|
||||
{
|
||||
$type = $this->scalarStringToTypeMapper->mapScalarStringToType($node->name);
|
||||
if ($type !== null) {
|
||||
return $type;
|
||||
}
|
||||
|
||||
return new MixedType();
|
||||
return $this->scalarStringToTypeMapper->mapScalarStringToType($node->name);
|
||||
}
|
||||
}
|
||||
|
@ -1,852 +0,0 @@
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
-
|
||||
message: "#^Unreachable statement \\- code above always terminates\\.$#"
|
||||
count: 1
|
||||
path: bin/rector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$keyName of method Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\Type\\\\AttributeAwareArrayShapeItemNode\\:\\:createKeyWithSpacePattern\\(\\) expects PHPStan\\\\PhpDocParser\\\\Ast\\\\ConstExpr\\\\ConstExprIntegerNode\\|PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\IdentifierTypeNode\\|null, PHPStan\\\\PhpDocParser\\\\Ast\\\\ConstExpr\\\\ConstExprIntegerNode\\|PHPStan\\\\PhpDocParser\\\\Ast\\\\ConstExpr\\\\ConstExprStringNode\\|PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\IdentifierTypeNode\\|null given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/Ast/Type/AttributeAwareArrayShapeItemNode.php
|
||||
|
||||
-
|
||||
message: "#^Property PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\ExtendsTagValueNode\\:\\:\\$type \\(PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\GenericTypeNode\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareExtendsTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$type of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\PhpDoc\\\\AttributeAwareExtendsTagValueNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\GenericTypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareExtendsTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Property PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\ImplementsTagValueNode\\:\\:\\$type \\(PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\GenericTypeNode\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareImplementsTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$type of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\PhpDoc\\\\AttributeAwareImplementsTagValueNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\GenericTypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareImplementsTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Array \\(array\\<PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\MethodTagValueParameterNode\\>\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMethodTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$returnType of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\PhpDoc\\\\AttributeAwareMethodTagValueNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\|null, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\|null given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMethodTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Property PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\MethodTagValueParameterNode\\:\\:\\$type \\(PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\|null\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMethodTagValueParameterNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$type of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\PhpDoc\\\\AttributeAwareMethodTagValueParameterNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\|null, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\|null given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMethodTagValueParameterNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Property PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\ParamTagValueNode\\:\\:\\$type \\(PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareParamTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$typeNode of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\PhpDoc\\\\AttributeAwareParamTagValueNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareParamTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Property PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PropertyTagValueNode\\:\\:\\$type \\(PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePropertyTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$type of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\PhpDoc\\\\AttributeAwarePropertyTagValueNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePropertyTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Property PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\ReturnTagValueNode\\:\\:\\$type \\(PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareReturnTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$type of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\PhpDoc\\\\AttributeAwareReturnTagValueNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareReturnTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Property PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\ThrowsTagValueNode\\:\\:\\$type \\(PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareThrowsTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$type of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\PhpDoc\\\\AttributeAwareThrowsTagValueNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareThrowsTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Property PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\VarTagValueNode\\:\\:\\$type \\(PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareVarTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$type of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\PhpDoc\\\\AttributeAwareVarTagValueNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/PhpDoc/AttributeAwareVarTagValueNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Property PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\ArrayShapeItemNode\\:\\:\\$valueType \\(PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareArrayShapeItemNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#3 \\$typeNode of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\Type\\\\AttributeAwareArrayShapeItemNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareArrayShapeItemNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Property PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\ArrayTypeNode\\:\\:\\$type \\(PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareArrayTypeNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$type of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\Type\\\\AttributeAwareArrayTypeNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareArrayTypeNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Array \\(array\\<PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\CallableTypeParameterNode\\>\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareCallableTypeNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$identifier of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\Type\\\\AttributeAwareCallableTypeNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\IdentifierTypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareCallableTypeNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#3 \\$returnType of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\Type\\\\AttributeAwareCallableTypeNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareCallableTypeNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Property PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\GenericTypeNode\\:\\:\\$type \\(PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\IdentifierTypeNode\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareGenericTypeNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$type of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\Type\\\\AttributeAwareGenericTypeNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\IdentifierTypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareGenericTypeNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Array \\(array\\<PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\>\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareIntersectionTypeNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Property PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\NullableTypeNode\\:\\:\\$type \\(PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareNullableTypeNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$type of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\Type\\\\AttributeAwareNullableTypeNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareNullableTypeNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Array \\(array\\<PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\\>\\) does not accept Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/attribute-aware-php-doc/src/AttributeAwareNodeFactory/Type/AttributeAwareUnionTypeNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Unreachable statement \\- code above always terminates\\.$#"
|
||||
count: 1
|
||||
path: packages/better-php-doc-parser/src/Annotation/AnnotationItemsResolver.php
|
||||
|
||||
-
|
||||
message: "#^PHPDoc tag @return with type PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocChildNode\\|PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocNode\\|PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocTagValueNode\\|Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface is not subtype of native type Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/better-php-doc-parser/src/Attributes/Ast/AttributeAwareNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Method Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\:\\:setAttribute\\(\\) has parameter \\$value with no typehint specified\\.$#"
|
||||
count: 1
|
||||
path: packages/better-php-doc-parser/src/Contract/PhpDocNode/AttributeAwareNodeInterface.php
|
||||
|
||||
-
|
||||
message: "#^Method Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\:\\:getAttribute\\(\\) has no return typehint specified\\.$#"
|
||||
count: 1
|
||||
path: packages/better-php-doc-parser/src/Contract/PhpDocNode/AttributeAwareNodeInterface.php
|
||||
|
||||
-
|
||||
message: "#^Method Rector\\\\BetterPhpDocParser\\\\PhpDocInfo\\\\PhpDocInfoFactory\\:\\:parseTokensToPhpDocNode\\(\\) should return Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\PhpDoc\\\\AttributeAwarePhpDocNode but returns PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocNode\\.$#"
|
||||
count: 1
|
||||
path: packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php
|
||||
|
||||
-
|
||||
message: "#^Do not use setter on a service$#"
|
||||
count: 1
|
||||
path: packages/better-php-doc-parser/src/PhpDocNodeFactory/ParamPhpDocNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$typeNode of class Rector\\\\AttributeAwarePhpDoc\\\\Ast\\\\PhpDoc\\\\AttributeAwareParamTagValueNode constructor expects PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode, Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/better-php-doc-parser/src/PhpDocNodeFactory/ParamPhpDocNodeFactory.php
|
||||
|
||||
-
|
||||
message: "#^Method Rector\\\\BetterPhpDocParser\\\\PhpDocParser\\\\BetterPhpDocParser\\:\\:parse\\(\\) should return PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocNode but returns Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/better-php-doc-parser/src/PhpDocParser/BetterPhpDocParser.php
|
||||
|
||||
-
|
||||
message: "#^Method Rector\\\\BetterPhpDocParser\\\\PhpDocParser\\\\BetterPhpDocParser\\:\\:parseTagValue\\(\\) should return PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocTagValueNode but returns Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/better-php-doc-parser/src/PhpDocParser/BetterPhpDocParser.php
|
||||
|
||||
-
|
||||
message: "#^PHPDoc tag @param for parameter \\$attributeAwareNode with type PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocTextNode\\|Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface is not subtype of native type Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\.$#"
|
||||
count: 1
|
||||
path: packages/better-php-doc-parser/src/Printer/MultilineSpaceFormatPreserver.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$attributeAwareNode of method Rector\\\\BetterPhpDocParser\\\\Printer\\\\PhpDocInfoPrinter\\:\\:printNode\\(\\) expects Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface, PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocChildNode\\|Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: packages/better-php-doc-parser/src/Printer/PhpDocInfoPrinter.php
|
||||
|
||||
-
|
||||
message: "#^PHPDoc tag @param for parameter \\$phpDocTagNode with type PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocTagNode\\|Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface is not subtype of native type PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocTagNode\\.$#"
|
||||
count: 1
|
||||
path: packages/better-php-doc-parser/src/Printer/PhpDocInfoPrinter.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocTagValueNode\\:\\:\\$description\\.$#"
|
||||
count: 2
|
||||
path: packages/better-php-doc-parser/src/Printer/PhpDocInfoPrinter.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\:\\:\\$children\\.$#"
|
||||
count: 2
|
||||
path: packages/better-php-doc-parser/tests/Attributes/Ast/AttributeAwareNodeFactoryTest.php
|
||||
|
||||
-
|
||||
message: "#^Method Rector\\\\Caching\\\\Detector\\\\ChangedFilesDetector\\:\\:hashFile\\(\\) should return string but returns string\\|false\\.$#"
|
||||
count: 1
|
||||
path: packages/caching/src/Detector/ChangedFilesDetector.php
|
||||
|
||||
-
|
||||
message: "#^Use value object over multi array assign$#"
|
||||
count: 1
|
||||
path: packages/node-collector/src/NodeCollector/ParsedClassConstFetchNodeCollector.php
|
||||
|
||||
-
|
||||
message: "#^Use `\\$class\\-\\>namespaceName` instead of `\\$class\\-\\>name` that only returns short class name$#"
|
||||
count: 1
|
||||
path: packages/node-name-resolver/src/NodeNameResolver/ClassNameResolver.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method getName\\(\\) on PHPStan\\\\Reflection\\\\ClassReflection\\|null\\.$#"
|
||||
count: 1
|
||||
path: packages/node-type-resolver/src/PHPStan/Scope/PHPStanNodeScopeResolver.php
|
||||
|
||||
-
|
||||
message: "#^Parameter 1 should use \"PHPStan\\\\PhpDocParser\\\\Ast\\\\Type\\\\TypeNode\" type as the only type passed to this method$#"
|
||||
count: 1
|
||||
path: packages/node-type-resolver/src/PhpDoc/PhpDocTypeRenamer.php
|
||||
|
||||
-
|
||||
message: "#^Result of \\|\\| is always true\\.$#"
|
||||
count: 1
|
||||
path: src/Rector/AbstractRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\\\FunctionLike\\|PhpParser\\\\Node\\\\Stmt\\\\ClassLike\\:\\:\\$stmts\\.$#"
|
||||
count: 2
|
||||
path: src/Rector/AbstractRector.php
|
||||
|
||||
-
|
||||
message: "#^Method Rector\\\\Core\\\\Rector\\\\AbstractRector\\:\\:getPhpDocTagValueNode\\(\\) should return PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocTagValueNode\\|null but return statement is missing\\.$#"
|
||||
count: 1
|
||||
path: src/Rector/AbstractRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter 2 should use \"PhpParser\\\\Node\\\\Expr\\\\MethodCall\" type as the only type passed to this method$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/NodeRemovingRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$name\\.$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/NodeRemovingRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$var\\.$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/NodeRemovingRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$args\\.$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/NodeRemovingRector.php
|
||||
|
||||
-
|
||||
message: "#^Instanceof between PhpParser\\\\Node\\\\Stmt and Rector\\\\Core\\\\PhpParser\\\\Node\\\\CustomNode\\\\FileWithoutNamespace will always evaluate to false\\.$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/UseAddingPostRector.php
|
||||
|
||||
-
|
||||
message: "#^Unreachable statement \\- code above always terminates\\.$#"
|
||||
count: 1
|
||||
path: packages/static-type-mapper/src/PhpParser/IdentifierNodeMapper.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access property \\$value on PhpParser\\\\Node\\\\Expr\\\\ArrayItem\\|null\\.$#"
|
||||
count: 2
|
||||
path: rules/cakephp/src/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access property \\$value on PhpParser\\\\Node\\\\Expr\\\\ArrayItem\\|null\\.$#"
|
||||
count: 2
|
||||
path: rules/code-quality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$expr\\.$#"
|
||||
count: 1
|
||||
path: rules/code-quality/src/Rector/ClassMethod/DateTimeToDateTimeInterfaceRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$right\\.$#"
|
||||
count: 2
|
||||
path: rules/code-quality/src/Rector/For_/ForToForeachRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$name of method Rector\\\\Core\\\\Rector\\\\AbstractRector\\:\\:isVariableName\\(\\) expects string, string\\|null given\\.$#"
|
||||
count: 2
|
||||
path: rules/code-quality/src/Rector/For_/ForToForeachRector.php
|
||||
|
||||
-
|
||||
message: "#^Method Rector\\\\CodeQuality\\\\Rector\\\\Foreach_\\\\SimplifyForeachToCoalescingRector\\:\\:matchReturnOrAssignNode\\(\\) should return PhpParser\\\\Node\\\\Expr\\\\Assign\\|PhpParser\\\\Node\\\\Stmt\\\\Return_\\|null but returns PhpParser\\\\Node\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/code-quality/src/Rector/Foreach_/SimplifyForeachToCoalescingRector.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access property \\$value on PhpParser\\\\Node\\\\Expr\\\\ArrayItem\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/code-quality/src/Rector/Foreach_/UnusedForeachValueToArrayKeysRector.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access property \\$value on PhpParser\\\\Node\\\\Expr\\\\ArrayItem\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/code-quality/src/Rector/FuncCall/SingleInArrayToCompareRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$expr\\.$#"
|
||||
count: 1
|
||||
path: rules/code-quality/src/Rector/FunctionLike/RemoveAlwaysTrueConditionSetInConstructorRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$cond\\.$#"
|
||||
count: 1
|
||||
path: rules/code-quality/src/Rector/If_/ShortenElseIfRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$stmts\\.$#"
|
||||
count: 1
|
||||
path: rules/code-quality/src/Rector/If_/ShortenElseIfRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$else\\.$#"
|
||||
count: 1
|
||||
path: rules/code-quality/src/Rector/If_/ShortenElseIfRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$elseifs\\.$#"
|
||||
count: 1
|
||||
path: rules/code-quality/src/Rector/If_/ShortenElseIfRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\\\Stmt\\:\\:\\$expr\\.$#"
|
||||
count: 4
|
||||
path: rules/code-quality/src/Rector/If_/SimplifyIfIssetToNullCoalescingRector.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access property \\$stmts on PhpParser\\\\Node\\\\Stmt\\\\Else_\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/code-quality/src/Rector/If_/SimplifyIfIssetToNullCoalescingRector.php
|
||||
|
||||
-
|
||||
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
|
||||
count: 1
|
||||
path: rules/code-quality/src/Rector/Name/FixClassCaseSensitivityNameRector.php
|
||||
|
||||
-
|
||||
message: "#^Strict comparison using \\=\\=\\= between PhpParser\\\\Node\\\\Expr and null will always evaluate to false\\.$#"
|
||||
count: 1
|
||||
path: rules/code-quality/src/Rector/Ternary/UnnecessaryTernaryExpressionRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$phpDocChildNode of method Rector\\\\CodingStyle\\\\ClassNameImport\\\\ShortNameResolver\\:\\:resolveShortTagNameFromPhpDocChildNode\\(\\) expects PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocChildNode, PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocChildNode\\|Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/ClassNameImport/ShortNameResolver.php
|
||||
|
||||
-
|
||||
message: "#^Use `\\$class\\-\\>namespaceName` instead of `\\$class\\-\\>name` that only returns short class name$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Naming/NameRenamer.php
|
||||
|
||||
-
|
||||
message: "#^If condition is always true\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Node/DocAliasResolver.php
|
||||
|
||||
-
|
||||
message: "#^Unreachable statement \\- code above always terminates\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/NodeAnalyzer/ThrowAnalyzer.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access property \\$value on PhpParser\\\\Node\\\\Expr\\\\ArrayItem\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/Assign/ManualJsonStringToJsonEncodeArrayRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$name\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$left of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\Greater constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$left of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\GreaterOrEqual constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$left of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\Identical constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$left of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\NotIdentical constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$left of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\Smaller constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$left of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\SmallerOrEqual constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$right of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\Greater constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$right of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\GreaterOrEqual constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$right of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\Identical constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$right of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\NotIdentical constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$right of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\Smaller constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$right of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\SmallerOrEqual constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node given\\.$#"
|
||||
count: 1
|
||||
path: rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$var\\.$#"
|
||||
count: 1
|
||||
path: rules/dead-code/src/NodeCollector/ModifiedVariableNamesCollector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$value\\.$#"
|
||||
count: 1
|
||||
path: rules/dead-code/src/NodeCollector/ModifiedVariableNamesCollector.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method getParentNode\\(\\) on Rector\\\\DeadCode\\\\ValueObject\\\\VariableNodeUse\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/dead-code/src/Rector/FunctionLike/RemoveOverriddenValuesRector.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access property \\$stmts on PhpParser\\\\Node\\\\Stmt\\\\Else_\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/dead-code/src/Rector/If_/SimplifyIfElseWithSameContentRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter 1 should use \"PhpParser\\\\Node\\\\Stmt\" type as the only type passed to this method$#"
|
||||
count: 1
|
||||
path: rules/dead-code/src/Rector/Stmt/RemoveUnreachableStatementRector.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"createFirstAssign\\(\\)\" is duplicated with method in \"Rector\\\\Defluent\\\\ValueObject\\\\FirstAssignFluentCall\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: rules/defluent/src/ValueObject/AssignAndRootExpr.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"getFirstAssign\\(\\)\" is duplicated with method in \"Rector\\\\Defluent\\\\ValueObject\\\\FirstAssignFluentCall\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: rules/defluent/src/ValueObject/AssignAndRootExpr.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"createAssign\\(\\)\" is duplicated with method in \"Rector\\\\Defluent\\\\ValueObject\\\\FirstAssignFluentCall\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: rules/defluent/src/ValueObject/AssignAndRootExpr.php
|
||||
|
||||
-
|
||||
message: "#^Offset 0 does not exist on array\\<PhpParser\\\\Node\\\\Stmt\\>\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/doctrine-code-quality/src/NodeAnalyzer/SetterClassMethodAnalyzer.php
|
||||
|
||||
-
|
||||
message: "#^Unreachable statement \\- code above always terminates\\.$#"
|
||||
count: 1
|
||||
path: rules/doctrine-code-quality/src/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method changeReturnType\\(\\) on Rector\\\\BetterPhpDocParser\\\\PhpDocInfo\\\\PhpDocInfo\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/SluggableBehaviorRector.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method addTagValueNodeWithShortName\\(\\) on Rector\\\\BetterPhpDocParser\\\\PhpDocInfo\\\\PhpDocInfo\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/TranslationBehaviorRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\\\Stmt\\:\\:\\$expr\\.$#"
|
||||
count: 2
|
||||
path: rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$args\\.$#"
|
||||
count: 1
|
||||
path: rules/doctrine/src/Rector/MethodCall/ChangeSetIdToUuidValueRector.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access property \\$value on PhpParser\\\\Node\\\\Expr\\\\ArrayItem\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/downgrade-php71/src/Rector/Array_/SymmetricArrayDestructuringToListRector.php
|
||||
|
||||
-
|
||||
message: "#^Unreachable statement \\- code above always terminates\\.$#"
|
||||
count: 1
|
||||
path: rules/downgrade-php71/src/Rector/String_/DowngradeNegativeStringOffsetToStrlenRector.php
|
||||
|
||||
-
|
||||
message: "#^Unreachable statement \\- code above always terminates\\.$#"
|
||||
count: 1
|
||||
path: rules/downgrade/src/Rector/LNumber/ChangePhpVersionInPlatformCheckRector.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access property \\$stmts on PhpParser\\\\Node\\\\Stmt\\\\Else_\\|null\\.$#"
|
||||
count: 3
|
||||
path: rules/early-return/src/Rector/If_/ChangeIfElseValueAssignToEarlyReturnRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\\\Stmt\\:\\:\\$expr\\.$#"
|
||||
count: 3
|
||||
path: rules/generic/src/Rector/ClassMethod/NormalToFluentRector.php
|
||||
|
||||
-
|
||||
message: "#^Use `\\$class\\-\\>namespaceName` instead of `\\$class\\-\\>name` that only returns short class name$#"
|
||||
count: 1
|
||||
path: rules/generic/src/Rector/Class_/ActionInjectionToConstructorInjectionRector.php
|
||||
|
||||
-
|
||||
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
|
||||
count: 1
|
||||
path: rules/generic/src/Rector/Property/InjectAnnotationClassRector.php
|
||||
|
||||
-
|
||||
message: "#^Unreachable statement \\- code above always terminates\\.$#"
|
||||
count: 1
|
||||
path: rules/generic/src/Rector/StaticCall/SwapClassMethodArgumentsRector.php
|
||||
|
||||
-
|
||||
message: "#^Offset 0 does not exist on array\\<PhpParser\\\\Node\\\\Stmt\\>\\|null\\.$#"
|
||||
count: 2
|
||||
path: rules/legacy/src/NodeAnalyzer/SingletonClassMethodAnalyzer.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$var\\.$#"
|
||||
count: 1
|
||||
path: rules/mockista-to-mockery/src/Rector/ClassMethod/MockistaMockToMockeryMockRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$var\\.$#"
|
||||
count: 1
|
||||
path: rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$variable of method Rector\\\\Naming\\\\Guard\\\\BreakingVariableRenameGuard\\:\\:isVariableAlreadyDefined\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\Variable, PhpParser\\\\Node\\\\Expr\\\\Error\\|PhpParser\\\\Node\\\\Expr\\\\Variable given\\.$#"
|
||||
count: 1
|
||||
path: rules/naming/src/Guard/BreakingVariableRenameGuard.php
|
||||
|
||||
-
|
||||
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
|
||||
count: 1
|
||||
path: rules/naming/src/Guard/BreakingVariableRenameGuard.php
|
||||
|
||||
-
|
||||
message: "#^Property with protected modifier is not allowed\\. Use interface contract method instead$#"
|
||||
count: 1
|
||||
path: rules/naming/src/Guard/PropertyConflictingNameGuard/AbstractPropertyConflictingNameGuard.php
|
||||
|
||||
-
|
||||
message: "#^Unreachable statement \\- code above always terminates\\.$#"
|
||||
count: 1
|
||||
path: rules/naming/src/Matcher/AbstractMatcher.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$expr\\.$#"
|
||||
count: 1
|
||||
path: rules/naming/src/Matcher/AbstractMatcher.php
|
||||
|
||||
-
|
||||
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
|
||||
count: 1
|
||||
path: rules/naming/src/Naming/ExpectedNameResolver.php
|
||||
|
||||
-
|
||||
message: "#^Property with protected modifier is not allowed\\. Use interface contract method instead$#"
|
||||
count: 1
|
||||
path: rules/naming/src/PropertyRenamer/AbstractPropertyRenamer.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$name\\.$#"
|
||||
count: 2
|
||||
path: rules/naming/src/PropertyRenamer/AbstractPropertyRenamer.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PhpParser\\\\Node\\:\\:\\$args\\.$#"
|
||||
count: 1
|
||||
path: rules/naming/src/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector.php
|
||||
|
||||
-
|
||||
message: "#^Offset 0 does not exist on array\\<PhpParser\\\\Node\\\\Stmt\\>\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/naming/src/Rector/ClassMethod/MakeGetterClassMethodNameStartWithGetRector.php
|
||||
|
||||
-
|
||||
message: "#^Offset 0 does not exist on array\\<PhpParser\\\\Node\\\\Stmt\\>\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/naming/src/Rector/ClassMethod/MakeIsserClassMethodNameStartWithIsRector.php
|
||||
|
||||
-
|
||||
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
|
||||
count: 1
|
||||
path: rules/naming/src/Rector/Property/UnderscoreToCamelCasePropertyNameRector.php
|
||||
|
||||
-
|
||||
message: "#^Result of \\|\\| is always true\\.$#"
|
||||
count: 1
|
||||
path: rules/naming/src/Rector/Variable/UnderscoreToCamelCaseLocalVariableNameRector.php
|
||||
|
||||
-
|
||||
message: "#^Unreachable statement \\- code above always terminates\\.$#"
|
||||
count: 1
|
||||
path: rules/naming/src/Rector/Variable/UnderscoreToCamelCaseVariableNameRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#4 \\$variable of class Rector\\\\Naming\\\\ValueObject\\\\ParamRename constructor expects PhpParser\\\\Node\\\\Expr\\\\Variable, PhpParser\\\\Node\\\\Expr\\\\Error\\|PhpParser\\\\Node\\\\Expr\\\\Variable given\\.$#"
|
||||
count: 1
|
||||
path: rules/naming/src/ValueObjectFactory/ParamRenameFactory.php
|
||||
|
||||
-
|
||||
message: "#^Offset 0 does not exist on array\\<PhpParser\\\\Node\\\\Stmt\\>\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/nette-kdyby/src/DataProvider/EventAndListenerTreeProvider.php
|
||||
|
||||
-
|
||||
message: "#^Use `\\$class\\-\\>namespaceName` instead of `\\$class\\-\\>name` that only returns short class name$#"
|
||||
count: 1
|
||||
path: rules/nette-kdyby/src/NodeFactory/EventValueObjectClassFactory.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$expr of method Rector\\\\Core\\\\PhpParser\\\\Node\\\\Value\\\\ValueResolver\\:\\:getValue\\(\\) expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node\\\\Expr\\|null given\\.$#"
|
||||
count: 1
|
||||
path: rules/nette-kdyby/src/NodeResolver/ListeningMethodsCollector.php
|
||||
|
||||
-
|
||||
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
|
||||
count: 1
|
||||
path: rules/nette-kdyby/src/NodeResolver/ListeningMethodsCollector.php
|
||||
|
||||
-
|
||||
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
|
||||
count: 1
|
||||
path: rules/nette-kdyby/src/Rector/ClassMethod/ReplaceMagicEventPropertySubscriberWithEventClassSubscriberRector.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access property \\$value on PhpParser\\\\Node\\\\Expr\\\\ArrayItem\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/nette-kdyby/src/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$nodes of method Rector\\\\Core\\\\PhpParser\\\\Node\\\\BetterNodeFinder\\:\\:find\\(\\) expects array\\<PhpParser\\\\Node\\>\\|PhpParser\\\\Node, array\\<PhpParser\\\\Node\\\\Stmt\\>\\|null given\\.$#"
|
||||
count: 1
|
||||
path: rules/nette-to-symfony/src/Rector/ClassMethod/RouterListToControllerAnnotationsRector.php
|
||||
|
||||
-
|
||||
message: "#^Use `\\$class\\-\\>namespaceName` instead of `\\$class\\-\\>name` that only returns short class name$#"
|
||||
count: 1
|
||||
path: rules/nette-to-symfony/src/Rector/Class_/NetteControlToSymfonyControllerRector.php
|
||||
|
||||
-
|
||||
message: "#^Class \"Rector\\\\Nette\\\\Rector\\\\Class_\\\\MoveFinalGetUserToCheckRequirementsClassMethodRector\" is missing @see annotation with test case class reference$#"
|
||||
count: 1
|
||||
path: rules/nette/src/Rector/Class_/MoveFinalGetUserToCheckRequirementsClassMethodRector.php
|
||||
|
||||
-
|
||||
message: "#^Unreachable statement \\- code above always terminates\\.$#"
|
||||
count: 1
|
||||
path: rules/nette/src/Rector/FuncCall/PregFunctionToNetteUtilsStringsRector.php
|
||||
|
||||
-
|
||||
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
|
||||
count: 1
|
||||
path: rules/php-spec-to-phpunit/src/Naming/PhpSpecRenaming.php
|
||||
|
||||
-
|
||||
message: "#^Use `\\$class\\-\\>namespaceName` instead of `\\$class\\-\\>name` that only returns short class name$#"
|
||||
count: 2
|
||||
path: rules/php-spec-to-phpunit/src/Naming/PhpSpecRenaming.php
|
||||
|
||||
-
|
||||
message: "#^Method Rector\\\\PhpSpecToPHPUnit\\\\Rector\\\\Class_\\\\PhpSpecClassToPHPUnitClassRector\\:\\:resolveFirstNonExpressionStmt\\(\\) has parameter \\$stmts with no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
path: rules/php-spec-to-phpunit/src/Rector/Class_/PhpSpecClassToPHPUnitClassRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$variable of method Rector\\\\PhpSpecToPHPUnit\\\\PhpSpecMockCollector\\:\\:isVariableMockInProperty\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\Variable, PhpParser\\\\Node\\\\Expr\\\\Error\\|PhpParser\\\\Node\\\\Expr\\\\Variable given\\.$#"
|
||||
count: 1
|
||||
path: rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecMocksToPHPUnitMocksRector.php
|
||||
|
||||
-
|
||||
message: "#^Negated boolean expression is always true\\.$#"
|
||||
count: 1
|
||||
path: rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecPromisesToPHPUnitAssertRector.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access property \\$value on PhpParser\\\\Node\\\\Expr\\\\ArrayItem\\|null\\.$#"
|
||||
count: 1
|
||||
path: rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecPromisesToPHPUnitAssertRector.php
|
||||
|
||||
-
|
||||
message: "#^Array \\(array\\<PhpParser\\\\Node\\\\Stmt\\>\\) does not accept PhpParser\\\\Node\\.$#"
|
||||
count: 1
|
||||
path: rules/php52/src/Rector/Switch_/ContinueToBreakInSwitchRector.php
|
||||
|
||||
-
|
||||
message: "#^Call to function in_array\\(\\) with arguments string, array\\(\\) and true will always evaluate to false\\.$#"
|
||||
count: 1
|
||||
path: rules/php56/src/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$left of class PhpParser\\\\Node\\\\Expr\\\\BinaryOp\\\\Spaceship constructor expects PhpParser\\\\Node\\\\Expr, PhpParser\\\\Node\\\\Expr\\|null given\\.$#"
|
||||
count: 1
|
||||
path: rules/php70/src/Rector/If_/IfToSpaceshipRector.php
|
||||
|
||||
-
|
||||
message: "#^Access to an undefined property PHPStan\\\\PhpDocParser\\\\Ast\\\\PhpDoc\\\\PhpDocTagNode\\|Rector\\\\BetterPhpDocParser\\\\Contract\\\\PhpDocNode\\\\AttributeAwareNodeInterface\\:\\:\\$value\\.$#"
|
||||
count: 1
|
||||
path: rules/phpunit/src/Rector/Class_/AddSeeTestAnnotationRector.php
|
||||
|
||||
-
|
||||
message: "#^Property Rector\\\\Core\\\\PhpParser\\\\Node\\\\CustomNode\\\\FileWithoutNamespace\\:\\:\\$stmts \\(array\\<PhpParser\\\\Node\\\\Stmt\\>\\) does not accept array\\<PhpParser\\\\Node\\>\\.$#"
|
||||
count: 1
|
||||
path: rules/renaming/src/Rector/FileWithoutNamespace/PseudoNamespaceToNamespaceRector.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$name of method Rector\\\\Core\\\\Rector\\\\AbstractRector\\:\\:getShortName\\(\\) expects PhpParser\\\\Node\\\\Identifier\\|PhpParser\\\\Node\\\\Name\\|string, PhpParser\\\\Node\\\\Identifier\\|null given\\.$#"
|
||||
count: 1
|
||||
path: rules/symfony-code-quality/src/Rector/Class_/EventListenerToEventSubscriberRector.php
|
||||
|
||||
-
|
||||
message: "#^Use `\\$class\\-\\>namespaceName` instead of `\\$class\\-\\>name` that only returns short class name$#"
|
||||
count: 1
|
||||
path: rules/symfony-code-quality/src/Rector/Class_/EventListenerToEventSubscriberRector.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"autowireNameResolverTrait\\(\\)\" is duplicated with method in \"Rector\\\\Core\\\\Rector\\\\AbstractRector\\\\NameResolverTrait\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/AbstractPostRector.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"isLocalMethodCallNamed\\(\\)\" is duplicated with method in \"Rector\\\\Core\\\\Rector\\\\AbstractRector\\\\NameResolverTrait\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/AbstractPostRector.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"isLocalMethodCallsNamed\\(\\)\" is duplicated with method in \"Rector\\\\Core\\\\Rector\\\\AbstractRector\\\\NameResolverTrait\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/AbstractPostRector.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"isFuncCallName\\(\\)\" is duplicated with method in \"Rector\\\\Core\\\\Rector\\\\AbstractRector\\\\NameResolverTrait\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/AbstractPostRector.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"isClassConstReference\\(\\)\" is duplicated with method in \"Rector\\\\Core\\\\Rector\\\\AbstractRector\\\\NameResolverTrait\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/AbstractPostRector.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"isStaticCallNamed\\(\\)\" is duplicated with method in \"Rector\\\\Core\\\\Rector\\\\AbstractRector\\\\NameResolverTrait\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/AbstractPostRector.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"isStaticCallsNamed\\(\\)\" is duplicated with method in \"Rector\\\\Core\\\\Rector\\\\AbstractRector\\\\NameResolverTrait\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/AbstractPostRector.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"isMethodCall\\(\\)\" is duplicated with method in \"Rector\\\\Core\\\\Rector\\\\AbstractRector\\\\NameResolverTrait\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/AbstractPostRector.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"isVariableName\\(\\)\" is duplicated with method in \"Rector\\\\Core\\\\Rector\\\\AbstractRector\\\\NameResolverTrait\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/AbstractPostRector.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"isInClassNamed\\(\\)\" is duplicated with method in \"Rector\\\\Core\\\\Rector\\\\AbstractRector\\\\NameResolverTrait\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/AbstractPostRector.php
|
||||
|
||||
-
|
||||
message: "#^Content of method \"isInClassesNamed\\(\\)\" is duplicated with method in \"Rector\\\\Core\\\\Rector\\\\AbstractRector\\\\NameResolverTrait\" class\\. Use unique content or abstract service instead$#"
|
||||
count: 1
|
||||
path: packages/post-rector/src/Rector/AbstractPostRector.php
|
||||
|
82
phpstan.neon
82
phpstan.neon
@ -1,6 +1,4 @@
|
||||
includes:
|
||||
- phpstan-baseline.neon
|
||||
|
||||
- utils/phpstan-extensions/config/phpstan-extensions.neon
|
||||
# allows symplify error formatter
|
||||
- vendor/symplify/phpstan-extensions/config/config.neon
|
||||
@ -610,3 +608,83 @@ parameters:
|
||||
path: src/PhpParser/Printer/BetterStandardPrinter.php
|
||||
|
||||
- '#Parameter \#1 \$node of method Rector\\Php80\\Rector\\If_\\NullsafeOperatorRector\:\:getStartNode\(\) expects PhpParser\\Node, PhpParser\\Node\|null given#'
|
||||
|
||||
# @todo resolve in symplify
|
||||
- '#Content of method "(.*?)\(\)" is duplicated with method in "(.*?)Trait" class\. Use unique content or abstract service instead#'
|
||||
|
||||
# known values from other methods
|
||||
-
|
||||
message: '#Negated boolean expression is always true#'
|
||||
path: rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecPromisesToPHPUnitAssertRector.php
|
||||
|
||||
-
|
||||
message: '#Call to function in_array\(\) with arguments string, array\(\) and true will always evaluate to false#'
|
||||
path: rules/php56/src/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php
|
||||
|
||||
-
|
||||
message: '#Parameter \#1 \$left of class PhpParser\\Node\\Expr\\BinaryOp\\Spaceship constructor expects PhpParser\\Node\\Expr, PhpParser\\Node\\Expr\|null given#'
|
||||
path: rules/php70/src/Rector/If_/IfToSpaceshipRector.php
|
||||
|
||||
- '#PhpParser\\Node\\Expr\\Error\|PhpParser\\Node\\Expr\\Variable given#'
|
||||
|
||||
# unable to test, because the method is final
|
||||
- '#Class "Rector\\Nette\\Rector\\Class_\\MoveFinalGetUserToCheckRequirementsClassMethodRector" is missing @see annotation with test case class reference#'
|
||||
|
||||
# type juggling
|
||||
- '#AttributeAwareNodeInterface#'
|
||||
- '#Method Rector\\Doctrine\\Rector\\MethodCall\\ChangeSetIdToUuidValueRector\:\:getSetUuidMethodCallOnSameVariable\(\) should return PhpParser\\Node\\Expr\\MethodCall\|null but returns PhpParser\\Node\|null#'
|
||||
|
||||
-
|
||||
message: '#Use `\$class\-\>namespaceName` instead of `\$class\-\>name` that only returns short class name#'
|
||||
paths:
|
||||
- rules/coding-style/src/Naming/NameRenamer.php
|
||||
- packages/node-name-resolver/src/NodeNameResolver/ClassNameResolver.php
|
||||
|
||||
-
|
||||
message: '#Property with protected modifier is not allowed\. Use interface contract method instead#'
|
||||
paths:
|
||||
- rules/defluent/src/ValueObject/*
|
||||
|
||||
- '#Parameter \#1 \$keyName of method Rector\\AttributeAwarePhpDoc\\Ast\\Type\\AttributeAwareArrayShapeItemNode\:\:createKeyWithSpacePattern\(\) expects PHPStan\\PhpDocParser\\Ast\\ConstExpr\\ConstExprIntegerNode\|PHPStan\\PhpDocParser\\Ast\\Type\\IdentifierTypeNode\|null, PHPStan\\PhpDocParser\\Ast\\ConstExpr\\ConstExprIntegerNode\|PHPStan\\PhpDocParser\\Ast\\ConstExpr\\ConstExprStringNode\|PHPStan\\PhpDocParser\\Ast\\Type\\IdentifierTypeNode\|null given#'
|
||||
- '#AttributeAwarePhpDocNode#'
|
||||
|
||||
# doc types
|
||||
-
|
||||
message: '#Access to an undefined property PhpParser\\Node\:\:\$args#'
|
||||
paths:
|
||||
- rules/naming/src/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector.php
|
||||
- '#Method Rector\\CodeQuality\\Rector\\Foreach_\\SimplifyForeachToCoalescingRector\:\:matchReturnOrAssignNode\(\) should return PhpParser\\Node\\Expr\\Assign\|PhpParser\\Node\\Stmt\\Return_\|null but returns PhpParser\\Node\|null#'
|
||||
- '#Cognitive complexity for "Rector\\CodeQuality\\Rector\\If_\\SimplifyIfIssetToNullCoalescingRector\:\:shouldSkip\(\)" is 10, keep it under 9#'
|
||||
- '#Instanceof between PhpParser\\Node\\Stmt and Rector\\Core\\PhpParser\\Node\\CustomNode\\FileWithoutNamespace will always evaluate to false#'
|
||||
|
||||
-
|
||||
message: '#Use value object over multi array assign#'
|
||||
paths:
|
||||
- packages/node-collector/src/NodeCollector/ParsedClassConstFetchNodeCollector.php
|
||||
|
||||
# @todo improvate later
|
||||
- '#Access to an undefined property PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagValueNode\:\:\$description#'
|
||||
|
||||
-
|
||||
message: '#Unreachable statement \- code above always terminates#'
|
||||
path: 'bin/rector.php'
|
||||
|
||||
-
|
||||
message: '#Do not use setter on a service#'
|
||||
paths:
|
||||
- packages/better-php-doc-parser/src/PhpDocNodeFactory/ParamPhpDocNodeFactory.php
|
||||
|
||||
|
||||
-
|
||||
message: '#Class cognitive complexity is 42, keep it under 40#'
|
||||
paths:
|
||||
- rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecPromisesToPHPUnitAssertRector.php
|
||||
|
||||
# @todo fix later
|
||||
-
|
||||
message: '#Property with protected modifier is not allowed\. Use interface contract method instead#'
|
||||
paths:
|
||||
- rules/naming/src/Guard/PropertyConflictingNameGuard/AbstractPropertyConflictingNameGuard.php
|
||||
- rules/naming/src/PropertyRenamer/AbstractPropertyRenamer.php
|
||||
|
||||
- '#Cannot call method getParentNode\(\) on Rector\\DeadCode\\ValueObject\\VariableNodeUse\|null#'
|
||||
|
@ -6,8 +6,10 @@ namespace Rector\CakePHP\Rector\Property;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\PropertyProperty;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Util\StaticRectorStrings;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
@ -65,27 +67,38 @@ CODE_SAMPLE
|
||||
if ($classLike === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isName($node, 'fixtures')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($node->props as $prop) {
|
||||
if (! $prop->default instanceof Array_) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($prop->default->items as $item) {
|
||||
if (! $item->value instanceof String_) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->renameFixtureName($item->value);
|
||||
}
|
||||
$this->refactorPropertyWithArrayDefault($prop);
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function refactorPropertyWithArrayDefault(PropertyProperty $propertyProperty): void
|
||||
{
|
||||
if (! $propertyProperty->default instanceof Array_) {
|
||||
return;
|
||||
}
|
||||
|
||||
$array = $propertyProperty->default;
|
||||
foreach ($array->items as $arrayItem) {
|
||||
if (! $arrayItem instanceof ArrayItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $arrayItem->value instanceof String_) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->renameFixtureName($arrayItem->value);
|
||||
}
|
||||
}
|
||||
|
||||
private function renameFixtureName(String_ $string): void
|
||||
{
|
||||
[$prefix, $table] = explode('.', $string->value);
|
||||
|
@ -8,6 +8,7 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\ClosureUse;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
@ -102,12 +103,22 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
|
||||
$objectVariable = $node->items[0]->value;
|
||||
$firstArrayItem = $node->items[0];
|
||||
if (! $firstArrayItem instanceof ArrayItem) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$objectVariable = $firstArrayItem->value;
|
||||
if (! $objectVariable instanceof Variable && ! $objectVariable instanceof PropertyFetch) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$methodName = $node->items[1]->value;
|
||||
$secondArrayItem = $node->items[1];
|
||||
if (! $secondArrayItem instanceof ArrayItem) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$methodName = $secondArrayItem->value;
|
||||
if (! $methodName instanceof String_) {
|
||||
return null;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\NullableType;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\UnionType;
|
||||
@ -34,6 +35,9 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
*/
|
||||
final class DateTimeToDateTimeInterfaceRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private const METHODS_RETURNING_CLASS_INSTANCE_MAP = [
|
||||
'add', 'modify', MethodName::SET_STATE, 'setDate', 'setISODate', 'setTime', 'setTimestamp', 'setTimezone', 'sub',
|
||||
];
|
||||
@ -172,14 +176,18 @@ CODE_SAMPLE
|
||||
|
||||
$assign = new Assign(new Variable($paramName), $methodCall);
|
||||
|
||||
/** @var Node $parentNode */
|
||||
$parentNode = $methodCall->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof Arg) {
|
||||
$parentNode->value = $assign;
|
||||
/** @var Node $parent */
|
||||
$parent = $methodCall->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parent instanceof Arg) {
|
||||
$parent->value = $assign;
|
||||
return;
|
||||
}
|
||||
|
||||
$parentNode->expr = $assign;
|
||||
if (! $parent instanceof Expression) {
|
||||
return;
|
||||
}
|
||||
|
||||
$parent->expr = $assign;
|
||||
}
|
||||
|
||||
private function shouldSkipMethodCallRefactor(string $paramName, MethodCall $methodCall): bool
|
||||
|
@ -10,6 +10,7 @@ use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\BinaryOp;
|
||||
use PhpParser\Node\Expr\BinaryOp\Greater;
|
||||
use PhpParser\Node\Expr\BinaryOp\Smaller;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
@ -222,6 +223,10 @@ CODE_SAMPLE
|
||||
return $this->isSmallerOrGreater($condExprs, $this->keyValueName, $this->countValueName);
|
||||
}
|
||||
|
||||
if (! $condExprs[0] instanceof BinaryOp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// count($values)
|
||||
if ($this->isFuncCallName($condExprs[0]->right, self::COUNT)) {
|
||||
/** @var FuncCall $countFuncCall */
|
||||
@ -272,9 +277,15 @@ CODE_SAMPLE
|
||||
if (! $node instanceof Assign) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $node->var instanceof ArrayDimFetch) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->keyValueName === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
return $this->isVariableName($node->var->dim, $this->keyValueName);
|
||||
}
|
||||
);
|
||||
@ -341,6 +352,10 @@ CODE_SAMPLE
|
||||
}
|
||||
|
||||
// is dim same as key value name, ...[$i]
|
||||
if ($this->keyValueName === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
if (! $this->isVariableName($node->dim, $this->keyValueName)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ namespace Rector\CodeQuality\Rector\Foreach_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Foreach_;
|
||||
use PHPStan\Type\ObjectType;
|
||||
@ -97,6 +98,10 @@ CODE_SAMPLE
|
||||
private function refactorArrayForeachValue(Array_ $array, Foreach_ $foreach): Array_
|
||||
{
|
||||
foreach ($array->items as $key => $arrayItem) {
|
||||
if (! $arrayItem instanceof ArrayItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $arrayItem->value;
|
||||
if (! $value instanceof Variable) {
|
||||
return $array;
|
||||
|
@ -6,6 +6,7 @@ namespace Rector\CodeQuality\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\BinaryOp\Equal;
|
||||
use PhpParser\Node\Expr\BinaryOp\Identical;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
@ -79,12 +80,17 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
|
||||
$onlyArrayItem = $arrayNode->items[0]->value;
|
||||
// strict
|
||||
if (isset($node->args[2])) {
|
||||
return new Identical($node->args[0]->value, $onlyArrayItem);
|
||||
$firstArrayItem = $arrayNode->items[0];
|
||||
if (! $firstArrayItem instanceof ArrayItem) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Equal($node->args[0]->value, $onlyArrayItem);
|
||||
$firstArrayItemValue = $firstArrayItem->value;
|
||||
// strict
|
||||
if (isset($node->args[2])) {
|
||||
return new Identical($node->args[0]->value, $firstArrayItemValue);
|
||||
}
|
||||
|
||||
return new Equal($node->args[0]->value, $firstArrayItemValue);
|
||||
}
|
||||
}
|
||||
|
@ -242,6 +242,10 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $node instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$resolvedTypes[] = $this->getStaticType($node->expr);
|
||||
return null;
|
||||
});
|
||||
|
@ -69,7 +69,7 @@ CODE_SAMPLE
|
||||
return $this->shortenElseIf($node);
|
||||
}
|
||||
|
||||
private function shortenElseIf(If_ $node): ?Node
|
||||
private function shortenElseIf(If_ $node): ?If_
|
||||
{
|
||||
if ($node->else === null) {
|
||||
return null;
|
||||
|
@ -78,10 +78,26 @@ CODE_SAMPLE
|
||||
$valueNode = $issetNode->vars[0];
|
||||
|
||||
// various scenarios
|
||||
$ifFirstStmt = $node->stmts[0];
|
||||
if (! $ifFirstStmt instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$else = $node->else;
|
||||
if (! $else instanceof Else_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$elseFirstStmt = $else->stmts[0];
|
||||
if (! $elseFirstStmt instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Assign $firstAssign */
|
||||
$firstAssign = $node->stmts[0]->expr;
|
||||
$firstAssign = $ifFirstStmt->expr;
|
||||
|
||||
/** @var Assign $secondAssign */
|
||||
$secondAssign = $node->else->stmts[0]->expr;
|
||||
$secondAssign = $elseFirstStmt->expr;
|
||||
|
||||
// 1. array_merge
|
||||
if (! $firstAssign->expr instanceof FuncCall) {
|
||||
@ -128,10 +144,29 @@ CODE_SAMPLE
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! $this->areNodesEqual($if->cond->vars[0], $if->stmts[0]->expr->var)) {
|
||||
$ifStmt = $if->stmts[0];
|
||||
if (! $ifStmt instanceof Expression) {
|
||||
return true;
|
||||
}
|
||||
return ! $this->areNodesEqual($if->cond->vars[0], $if->else->stmts[0]->expr->var);
|
||||
|
||||
if (! $ifStmt->expr instanceof Assign) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! $this->areNodesEqual($if->cond->vars[0], $ifStmt->expr->var)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$firstElseStmt = $if->else->stmts[0];
|
||||
if (! $firstElseStmt instanceof Expression) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $firstElseStmt->expr instanceof Assign) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ! $this->areNodesEqual($if->cond->vars[0], $firstElseStmt->expr->var);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,10 +86,6 @@ CODE_SAMPLE
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$fullyQualifiedName = $this->resolveFullyQualifiedName($node);
|
||||
if ($fullyQualifiedName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->reflectionProvider->hasClass($fullyQualifiedName)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -59,12 +59,12 @@ final class UnnecessaryTernaryExpressionRector extends AbstractRector
|
||||
}
|
||||
|
||||
$ifExpression = $ternaryExpression->if;
|
||||
if ($ifExpression === null) {
|
||||
if (! $this->isBool($ifExpression)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$elseExpression = $ternaryExpression->else;
|
||||
if (! $this->isBool($ifExpression) || ! $this->isBool($elseExpression)) {
|
||||
if (! $this->isBool($elseExpression)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ namespace Rector\CodingStyle\Naming;
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Util\StaticRectorStrings;
|
||||
@ -42,10 +43,18 @@ final class ClassNaming
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|Name|Identifier $name
|
||||
* @param string|Name|Identifier|ClassLike $name
|
||||
*/
|
||||
public function getShortName($name): string
|
||||
{
|
||||
if ($name instanceof ClassLike) {
|
||||
if ($name->name === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->getShortName($name->name);
|
||||
}
|
||||
|
||||
if ($name instanceof Name || $name instanceof Identifier) {
|
||||
$name = $this->nodeNameResolver->getName($name);
|
||||
if ($name === null) {
|
||||
|
@ -49,9 +49,7 @@ final class DocAliasResolver
|
||||
/** @var PhpDocInfo $phpDocInfo */
|
||||
$phpDocInfo = $node->getAttribute(AttributeKey::PHP_DOC_INFO);
|
||||
|
||||
if ($phpDocInfo->getVarType()) {
|
||||
$possibleDocAliases = $this->collectVarType($phpDocInfo, $possibleDocAliases);
|
||||
}
|
||||
$possibleDocAliases = $this->collectVarType($phpDocInfo, $possibleDocAliases);
|
||||
|
||||
// e.g. "use Dotrine\ORM\Mapping as ORM" etc.
|
||||
$matches = Strings::matchAll($docComment->getText(), self::DOC_ALIAS_REGEX);
|
||||
|
@ -9,7 +9,6 @@ use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\Exception\NotImplementedYetException;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
@ -46,11 +45,7 @@ final class ThrowAnalyzer
|
||||
}
|
||||
|
||||
$class = $this->resolveClassFromType($thrownType);
|
||||
if ($class !== null) {
|
||||
return [$class];
|
||||
}
|
||||
|
||||
throw new NotImplementedYetException(get_class($thrownType));
|
||||
return [$class];
|
||||
}
|
||||
|
||||
private function resolveClassFromType(Type $thrownType): string
|
||||
@ -63,8 +58,6 @@ final class ThrowAnalyzer
|
||||
return $thrownType->getClassName();
|
||||
}
|
||||
|
||||
dump($thrownType);
|
||||
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ use Rector\CodingStyle\Node\ConcatJoiner;
|
||||
use Rector\CodingStyle\Node\ConcatManipulator;
|
||||
use Rector\CodingStyle\ValueObject\ConcatExpressionJoinData;
|
||||
use Rector\CodingStyle\ValueObject\NodeToRemoveAndConcatItem;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
@ -324,7 +325,12 @@ CODE_SAMPLE
|
||||
// traverse and replace placeholder by original nodes
|
||||
$this->traverseNodesWithCallable($array, function (Node $node) use ($placeholderNodes): ?Expr {
|
||||
if ($node instanceof Array_ && count((array) $node->items) === 1) {
|
||||
$placeholderNode = $this->matchPlaceholderNode($node->items[0]->value, $placeholderNodes);
|
||||
$onlyItem = $node->items[0];
|
||||
if ($onlyItem === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$placeholderNode = $this->matchPlaceholderNode($onlyItem->value, $placeholderNodes);
|
||||
|
||||
if ($placeholderNode && $this->isImplodeToJson($placeholderNode)) {
|
||||
/** @var FuncCall $placeholderNode */
|
||||
|
@ -6,6 +6,7 @@ namespace Rector\CodingStyle\Rector\Catch_;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Catch_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
@ -120,6 +121,10 @@ CODE_SAMPLE
|
||||
$oldVariableName,
|
||||
$newVariableName
|
||||
): void {
|
||||
if (! $node instanceof Variable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->isVariableName($node, $oldVariableName)) {
|
||||
return;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ CODE_SAMPLE
|
||||
return $expr->name->toString() === 'PHP_VERSION';
|
||||
}
|
||||
|
||||
private function getNewNodeForArg(Expr $expr): Node
|
||||
private function getNewNodeForArg(Expr $expr): Expr
|
||||
{
|
||||
if ($this->isPhpVersionConstant($expr)) {
|
||||
return new ConstFetch(new Name('PHP_VERSION_ID'));
|
||||
|
@ -9,6 +9,7 @@ use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt;
|
||||
use Rector\Core\PhpParser\NodeTraverser\CallableNodeTraverser;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
@ -34,53 +35,75 @@ final class ModifiedVariableNamesCollector
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function collectModifiedVariableNames(Node $node): array
|
||||
public function collectModifiedVariableNames(Stmt $stmt): array
|
||||
{
|
||||
$argNames = $this->collectFromArgs($stmt);
|
||||
$assignNames = $this->collectFromAssigns($stmt);
|
||||
|
||||
return array_merge($argNames, $assignNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function collectFromArgs(Stmt $stmt): array
|
||||
{
|
||||
$variableNames = [];
|
||||
|
||||
$this->callableNodeTraverser->traverseNodesWithCallable($stmt, function (Node $node) use (
|
||||
&$variableNames
|
||||
) {
|
||||
if (! $node instanceof Arg) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isVariableChangedInReference($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$variableName = $this->nodeNameResolver->getName($node->value);
|
||||
if ($variableName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$variableNames[] = $variableName;
|
||||
});
|
||||
|
||||
return $variableNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function collectFromAssigns(Stmt $stmt): array
|
||||
{
|
||||
$modifiedVariableNames = [];
|
||||
|
||||
$this->callableNodeTraverser->traverseNodesWithCallable($node, function (Node $node) use (
|
||||
$this->callableNodeTraverser->traverseNodesWithCallable($stmt, function (Node $node) use (
|
||||
&$modifiedVariableNames
|
||||
) {
|
||||
if ($this->isVariableOverriddenInAssign($node)) {
|
||||
/** @var Assign $node */
|
||||
$variableName = $this->nodeNameResolver->getName($node->var);
|
||||
if ($variableName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$modifiedVariableNames[] = $variableName;
|
||||
if (! $node instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->isVariableChangedInReference($node)) {
|
||||
/** @var Arg $node */
|
||||
$variableName = $this->nodeNameResolver->getName($node->value);
|
||||
if ($variableName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$modifiedVariableNames[] = $variableName;
|
||||
if (! $node->var instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$variableName = $this->nodeNameResolver->getName($node->var);
|
||||
if ($variableName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$modifiedVariableNames[] = $variableName;
|
||||
});
|
||||
|
||||
return $modifiedVariableNames;
|
||||
}
|
||||
|
||||
private function isVariableOverriddenInAssign(Node $node): bool
|
||||
private function isVariableChangedInReference(Arg $arg): bool
|
||||
{
|
||||
if (! $node instanceof Assign) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $node->var instanceof Variable;
|
||||
}
|
||||
|
||||
private function isVariableChangedInReference(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof Arg) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
$parentNode = $arg->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (! $parentNode instanceof FuncCall) {
|
||||
return false;
|
||||
}
|
||||
|
@ -184,8 +184,7 @@ CODE_SAMPLE
|
||||
|
||||
if ($this->isAssignNodeUsed($previousNode, $nodeByTypeAndPosition)) {
|
||||
// continue
|
||||
|
||||
// instant override → remove
|
||||
// instant override → remove
|
||||
} elseif ($this->shouldRemoveAssignNode($previousNode, $nodeByTypeAndPosition)) {
|
||||
/** @var VariableNodeUse $previousNode */
|
||||
$nodesToRemove[] = $previousNode->getParentNode();
|
||||
|
@ -6,6 +6,7 @@ namespace Rector\DeadCode\Rector\If_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
@ -85,7 +86,12 @@ CODE_SAMPLE
|
||||
$possibleContents[] = $this->print($elseif->stmts);
|
||||
}
|
||||
|
||||
$possibleContents[] = $this->print($if->else->stmts);
|
||||
$else = $if->else;
|
||||
if ($else === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$possibleContents[] = $this->print($else->stmts);
|
||||
|
||||
$uniqueContents = array_unique($possibleContents);
|
||||
|
||||
|
@ -127,7 +127,7 @@ CODE_SAMPLE
|
||||
// traverse up for unreachable node in the same scope
|
||||
$previousNode = $stmt->getAttribute(AttributeKey::PREVIOUS_STATEMENT);
|
||||
|
||||
while ($previousNode instanceof Node && ! $this->isBreakingScopeNode($previousNode)) {
|
||||
while ($previousNode instanceof Stmt && ! $this->isBreakingScopeNode($previousNode)) {
|
||||
$isUnreachable = $previousNode->getAttribute(AttributeKey::IS_UNREACHABLE);
|
||||
if ($isUnreachable === true) {
|
||||
return true;
|
||||
@ -164,20 +164,20 @@ CODE_SAMPLE
|
||||
/**
|
||||
* Check nodes that breaks scope while traversing up
|
||||
*/
|
||||
private function isBreakingScopeNode(Node $node): bool
|
||||
private function isBreakingScopeNode(Stmt $stmt): bool
|
||||
{
|
||||
if ($node instanceof ClassLike) {
|
||||
if ($stmt instanceof ClassLike) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($node instanceof ClassMethod) {
|
||||
if ($stmt instanceof ClassMethod) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($node instanceof Namespace_) {
|
||||
if ($stmt instanceof Namespace_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $node instanceof Else_;
|
||||
return $stmt instanceof Else_;
|
||||
}
|
||||
}
|
||||
|
111
rules/defluent/src/ValueObject/AbstractRootExpr.php
Normal file
111
rules/defluent/src/ValueObject/AbstractRootExpr.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Defluent\ValueObject;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Defluent\Contract\ValueObject\FirstCallFactoryAwareInterface;
|
||||
use Rector\Defluent\Contract\ValueObject\RootExprAwareInterface;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
|
||||
abstract class AbstractRootExpr implements RootExprAwareInterface, FirstCallFactoryAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $isFirstCallFactory = false;
|
||||
|
||||
/**
|
||||
* @var Expr
|
||||
*/
|
||||
protected $rootExpr;
|
||||
|
||||
/**
|
||||
* @var Expr
|
||||
*/
|
||||
protected $assignExpr;
|
||||
|
||||
public function createFirstAssign(): Assign
|
||||
{
|
||||
if ($this->isFirstCallFactory && $this->getFirstAssign() !== null) {
|
||||
return $this->createFactoryAssign();
|
||||
}
|
||||
|
||||
return $this->createAssign($this->assignExpr, $this->rootExpr);
|
||||
}
|
||||
|
||||
public function createAssign(Expr $assignVar, Expr $assignExpr): Assign
|
||||
{
|
||||
if ($assignVar === $assignExpr) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
return new Assign($assignVar, $assignExpr);
|
||||
}
|
||||
|
||||
protected function getFirstAssign(): ?Assign
|
||||
{
|
||||
$currentStmt = $this->assignExpr->getAttribute(AttributeKey::CURRENT_STATEMENT);
|
||||
if (! $currentStmt instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($currentStmt->expr instanceof Assign) {
|
||||
return $currentStmt->expr;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function createFactoryAssign(): Assign
|
||||
{
|
||||
/** @var Assign $firstAssign */
|
||||
$firstAssign = $this->getFirstAssign();
|
||||
$currentMethodCall = $firstAssign->expr;
|
||||
|
||||
if (! $currentMethodCall instanceof MethodCall) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$currentMethodCall = $this->resolveLastMethodCall($currentMethodCall);
|
||||
|
||||
// ensure var and expr are different
|
||||
$assignVar = $firstAssign->var;
|
||||
$assignExpr = $currentMethodCall;
|
||||
|
||||
return $this->createAssign($assignVar, $assignExpr);
|
||||
}
|
||||
|
||||
// private function createFactoryAssign(): Assign
|
||||
// {
|
||||
// /** @var Assign */
|
||||
// $firstAssign = $this->getFirstAssign();
|
||||
// $currentMethodCall = $firstAssign->expr;
|
||||
//
|
||||
// if (! $currentMethodCall instanceof MethodCall) {
|
||||
// throw new ShouldNotHappenException();
|
||||
// }
|
||||
//
|
||||
// $currentMethodCall = $this->fluentMethodCalls->getLastMethodCall();
|
||||
//
|
||||
// // ensure var and expr are different
|
||||
// $assignVar = $firstAssign->var;
|
||||
// $assignExpr = $currentMethodCall;
|
||||
//
|
||||
// return $this->createAssign($assignVar, $assignExpr);
|
||||
// }
|
||||
|
||||
private function resolveLastMethodCall(MethodCall $currentMethodCall): MethodCall
|
||||
{
|
||||
while ($currentMethodCall->var instanceof MethodCall) {
|
||||
$currentMethodCall = $currentMethodCall->var;
|
||||
}
|
||||
|
||||
return $currentMethodCall;
|
||||
}
|
||||
}
|
@ -5,33 +5,14 @@ declare(strict_types=1);
|
||||
namespace Rector\Defluent\ValueObject;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Defluent\Contract\ValueObject\FirstCallFactoryAwareInterface;
|
||||
use Rector\Defluent\Contract\ValueObject\RootExprAwareInterface;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
|
||||
final class AssignAndRootExpr implements RootExprAwareInterface, FirstCallFactoryAwareInterface
|
||||
final class AssignAndRootExpr extends AbstractRootExpr implements RootExprAwareInterface, FirstCallFactoryAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isFirstCallFactory = false;
|
||||
|
||||
/**
|
||||
* @var Expr
|
||||
*/
|
||||
private $assignExpr;
|
||||
|
||||
/**
|
||||
* @var Expr
|
||||
*/
|
||||
private $rootExpr;
|
||||
|
||||
/**
|
||||
* @var Variable|null
|
||||
*/
|
||||
@ -73,15 +54,6 @@ final class AssignAndRootExpr implements RootExprAwareInterface, FirstCallFactor
|
||||
return new Return_($this->silentVariable);
|
||||
}
|
||||
|
||||
public function createFirstAssign(): Assign
|
||||
{
|
||||
if ($this->isFirstCallFactory && $this->getFirstAssign() !== null) {
|
||||
return $this->createFactoryAssign();
|
||||
}
|
||||
|
||||
return $this->createAssign($this->assignExpr, $this->rootExpr);
|
||||
}
|
||||
|
||||
public function getCallerExpr(): Expr
|
||||
{
|
||||
if ($this->silentVariable !== null) {
|
||||
@ -105,55 +77,4 @@ final class AssignAndRootExpr implements RootExprAwareInterface, FirstCallFactor
|
||||
|
||||
return $firstAssign->var;
|
||||
}
|
||||
|
||||
private function getFirstAssign(): ?Assign
|
||||
{
|
||||
$currentStmt = $this->assignExpr->getAttribute(AttributeKey::CURRENT_STATEMENT);
|
||||
if (! $currentStmt instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($currentStmt->expr instanceof Assign) {
|
||||
return $currentStmt->expr;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function createFactoryAssign(): Assign
|
||||
{
|
||||
/** @var Assign $firstAssign */
|
||||
$firstAssign = $this->getFirstAssign();
|
||||
$currentMethodCall = $firstAssign->expr;
|
||||
|
||||
if (! $currentMethodCall instanceof MethodCall) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$currentMethodCall = $this->resolveLastMethodCall($currentMethodCall);
|
||||
|
||||
// ensure var and expr are different
|
||||
$assignVar = $firstAssign->var;
|
||||
$assignExpr = $currentMethodCall;
|
||||
|
||||
return $this->createAssign($assignVar, $assignExpr);
|
||||
}
|
||||
|
||||
private function createAssign(Expr $assignVar, Expr $assignExpr): Assign
|
||||
{
|
||||
if ($assignVar === $assignExpr) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
return new Assign($assignVar, $assignExpr);
|
||||
}
|
||||
|
||||
private function resolveLastMethodCall(MethodCall $currentMethodCall): MethodCall
|
||||
{
|
||||
while ($currentMethodCall->var instanceof MethodCall) {
|
||||
$currentMethodCall = $currentMethodCall->var;
|
||||
}
|
||||
|
||||
return $currentMethodCall;
|
||||
}
|
||||
}
|
||||
|
@ -5,31 +5,12 @@ declare(strict_types=1);
|
||||
namespace Rector\Defluent\ValueObject;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Defluent\Contract\ValueObject\FirstCallFactoryAwareInterface;
|
||||
use Rector\Defluent\Contract\ValueObject\RootExprAwareInterface;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
|
||||
final class FirstAssignFluentCall implements RootExprAwareInterface, FirstCallFactoryAwareInterface
|
||||
final class FirstAssignFluentCall extends AbstractRootExpr implements RootExprAwareInterface, FirstCallFactoryAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isFirstCallFactory = false;
|
||||
|
||||
/**
|
||||
* @var Expr
|
||||
*/
|
||||
private $assignExpr;
|
||||
|
||||
/**
|
||||
* @var Expr
|
||||
*/
|
||||
private $rootExpr;
|
||||
|
||||
/**
|
||||
* @var FluentMethodCalls
|
||||
*/
|
||||
@ -57,15 +38,6 @@ final class FirstAssignFluentCall implements RootExprAwareInterface, FirstCallFa
|
||||
return $this->rootExpr;
|
||||
}
|
||||
|
||||
public function createFirstAssign(): Assign
|
||||
{
|
||||
if ($this->isFirstCallFactory && $this->getFirstAssign() !== null) {
|
||||
return $this->createFactoryAssign();
|
||||
}
|
||||
|
||||
return $this->createAssign($this->assignExpr, $this->rootExpr);
|
||||
}
|
||||
|
||||
public function getCallerExpr(): Expr
|
||||
{
|
||||
return $this->assignExpr;
|
||||
@ -93,46 +65,4 @@ final class FirstAssignFluentCall implements RootExprAwareInterface, FirstCallFa
|
||||
{
|
||||
return $this->fluentMethodCalls->getFluentMethodCalls();
|
||||
}
|
||||
|
||||
private function getFirstAssign(): ?Assign
|
||||
{
|
||||
$currentStmt = $this->assignExpr->getAttribute(AttributeKey::CURRENT_STATEMENT);
|
||||
if (! $currentStmt instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($currentStmt->expr instanceof Assign) {
|
||||
return $currentStmt->expr;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function createFactoryAssign(): Assign
|
||||
{
|
||||
/** @var Assign $firstAssign */
|
||||
$firstAssign = $this->getFirstAssign();
|
||||
$currentMethodCall = $firstAssign->expr;
|
||||
|
||||
if (! $currentMethodCall instanceof MethodCall) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$currentMethodCall = $this->fluentMethodCalls->getLastMethodCall();
|
||||
|
||||
// ensure var and expr are different
|
||||
$assignVar = $firstAssign->var;
|
||||
$assignExpr = $currentMethodCall;
|
||||
|
||||
return $this->createAssign($assignVar, $assignExpr);
|
||||
}
|
||||
|
||||
private function createAssign(Expr $assignVar, Expr $assignExpr): Assign
|
||||
{
|
||||
if ($assignVar === $assignExpr) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
return new Assign($assignVar, $assignExpr);
|
||||
}
|
||||
}
|
||||
|
@ -121,11 +121,16 @@ final class SetterClassMethodAnalyzer
|
||||
return null;
|
||||
}
|
||||
|
||||
if (count((array) $classMethod->stmts) !== 1) {
|
||||
$stmts = (array) $classMethod->stmts;
|
||||
if (count($stmts) !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$onlyStmt = $stmts[0] ?? null;
|
||||
if ($onlyStmt === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$onlyStmt = $classMethod->stmts[0];
|
||||
if ($onlyStmt instanceof Expression) {
|
||||
$onlyStmt = $onlyStmt->expr;
|
||||
}
|
||||
|
@ -119,11 +119,7 @@ CODE_SAMPLE
|
||||
return $this->refactorProperty($node);
|
||||
}
|
||||
|
||||
if ($node instanceof ClassMethod) {
|
||||
return $this->refactorClassMethod($node);
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->refactorClassMethod($node);
|
||||
}
|
||||
|
||||
private function refactorProperty(Property $property): ?Property
|
||||
|
@ -157,7 +157,7 @@ CODE_SAMPLE
|
||||
$classMethod->stmts[] = new Return_($this->createArray($slugFields));
|
||||
|
||||
$returnType = new ArrayType(new MixedType(), new StringType());
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($classMethod);
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
|
||||
$phpDocInfo->changeReturnType($returnType);
|
||||
// $this->docBlockManipulator->addReturnTag($classMethod, new ArrayType(new MixedType(), new StringType()));
|
||||
|
||||
|
@ -266,7 +266,7 @@ CODE_SAMPLE
|
||||
'Knp\DoctrineBehaviors\Model\Translatable\TranslationTrait'
|
||||
);
|
||||
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($class);
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($class);
|
||||
$phpDocInfo->addTagValueNodeWithShortName(new EntityTagValueNode([]));
|
||||
|
||||
foreach ($translatedPropertyToPhpDocInfos as $translatedPropertyName => $translatedPhpDocInfo) {
|
||||
|
@ -267,7 +267,11 @@ CODE_SAMPLE
|
||||
private function removeRegistryDependencyAssign(Class_ $class, ClassMethod $classMethod, Param $registryParam): void
|
||||
{
|
||||
foreach ((array) $classMethod->stmts as $constructorMethodStmt) {
|
||||
if (! $constructorMethodStmt instanceof Expression && ! $constructorMethodStmt->expr instanceof Assign) {
|
||||
if (! $constructorMethodStmt instanceof Expression) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $constructorMethodStmt->expr instanceof Assign) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ CODE_SAMPLE
|
||||
return $this->isUuidType($methodCall->args[0]->value);
|
||||
}
|
||||
|
||||
private function getSetUuidMethodCallOnSameVariable(MethodCall $methodCall): ?Node
|
||||
private function getSetUuidMethodCallOnSameVariable(MethodCall $methodCall): ?MethodCall
|
||||
{
|
||||
$parentNode = $methodCall->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof Expression) {
|
||||
@ -171,7 +171,7 @@ CODE_SAMPLE
|
||||
/** @var ObjectType $variableType */
|
||||
$variableType = $this->getStaticType($methodCall->var);
|
||||
|
||||
return $this->betterNodeFinder->findFirst($parentNode, function (Node $node) use (
|
||||
$methodCall = $this->betterNodeFinder->findFirst($parentNode, function (Node $node) use (
|
||||
$variableName,
|
||||
$variableType
|
||||
): bool {
|
||||
@ -186,8 +186,15 @@ CODE_SAMPLE
|
||||
if (! $this->isObjectType($node->var, $variableType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isName($node->name, 'setUuid');
|
||||
});
|
||||
|
||||
if ($methodCall instanceof MethodCall) {
|
||||
return $methodCall;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function createUuidStringNode(): String_
|
||||
|
@ -7,6 +7,7 @@ namespace Rector\DowngradePhp71\Rector\Array_;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Name;
|
||||
@ -56,8 +57,12 @@ final class SymmetricArrayDestructuringToListRector extends AbstractRector
|
||||
private function processToList(Array_ $array): FuncCall
|
||||
{
|
||||
$args = [];
|
||||
foreach ($array->items as $item) {
|
||||
$args[] = new Arg($item->value);
|
||||
foreach ($array->items as $arrayItem) {
|
||||
if (! $arrayItem instanceof ArrayItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$args[] = new Arg($arrayItem->value);
|
||||
}
|
||||
|
||||
return new FuncCall(new Name('list'), $args);
|
||||
|
@ -60,11 +60,7 @@ CODE_SAMPLE
|
||||
return $this->processForString($node);
|
||||
}
|
||||
|
||||
if ($node instanceof FuncCall) {
|
||||
return $this->processForFuncCall($node);
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->processForFuncCall($node);
|
||||
}
|
||||
|
||||
private function processForString(String_ $string): ?String_
|
||||
|
@ -101,11 +101,7 @@ CODE_SAMPLE
|
||||
return $this->refactorLNumber($node);
|
||||
}
|
||||
|
||||
if ($node instanceof String_) {
|
||||
return $this->refactorString($node);
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->refactorString($node);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,8 +6,10 @@ namespace Rector\EarlyReturn\Rector\If_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Stmt\Else_;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\PhpParser\Node\Manipulator\IfManipulator;
|
||||
use Rector\Core\PhpParser\Node\Manipulator\StmtsManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
@ -109,12 +111,17 @@ CODE_SAMPLE
|
||||
$this->mirrorComments($return, $assign);
|
||||
$node->stmts[$lastIfStmtKey] = $return;
|
||||
|
||||
$else = $node->else;
|
||||
if (! $else instanceof Else_) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$elseStmts = (array) $else->stmts;
|
||||
|
||||
/** @var Assign $assign */
|
||||
$assign = $this->stmtsManipulator->getUnwrappedLastStmt($node->else->stmts);
|
||||
$assign = $this->stmtsManipulator->getUnwrappedLastStmt($elseStmts);
|
||||
|
||||
$lastElseStmtKey = array_key_last($node->else->stmts);
|
||||
|
||||
$elseStmts = $node->else->stmts;
|
||||
$lastElseStmtKey = array_key_last($elseStmts);
|
||||
|
||||
$return = new Return_($assign->expr);
|
||||
$this->mirrorComments($return, $assign);
|
||||
|
@ -6,10 +6,10 @@ namespace Rector\Generic\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Generic\ValueObject\NormalToFluent;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
@ -81,6 +81,7 @@ CODE_SAMPLE
|
||||
|
||||
// iterate from bottom to up, so we can merge
|
||||
for ($i = $classMethodStatementCount - 1; $i >= 0; --$i) {
|
||||
/** @var Expression $stmt */
|
||||
$stmt = $node->stmts[$i];
|
||||
if ($this->shouldSkipPreviousStmt($node, $i, $stmt)) {
|
||||
continue;
|
||||
@ -120,7 +121,7 @@ CODE_SAMPLE
|
||||
$this->callsToFluent = $callsToFluent;
|
||||
}
|
||||
|
||||
private function shouldSkipPreviousStmt(ClassMethod $classMethod, int $i, Stmt $stmt): bool
|
||||
private function shouldSkipPreviousStmt(ClassMethod $classMethod, int $i, Expression $expression): bool
|
||||
{
|
||||
// we look only for 2+ stmts
|
||||
if (! isset($classMethod->stmts[$i - 1])) {
|
||||
@ -128,7 +129,7 @@ CODE_SAMPLE
|
||||
}
|
||||
|
||||
// we look for 2 methods calls in a row
|
||||
if (! $stmt instanceof Expression) {
|
||||
if (! $expression instanceof Expression) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -137,22 +138,22 @@ CODE_SAMPLE
|
||||
return ! $prevStmt instanceof Expression;
|
||||
}
|
||||
|
||||
private function isBothMethodCallMatch(Stmt $firstStmt, Expression $expression): bool
|
||||
private function isBothMethodCallMatch(Expression $firstExpression, Expression $secondExpression): bool
|
||||
{
|
||||
if (! $firstStmt->expr instanceof MethodCall) {
|
||||
if (! $firstExpression->expr instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $expression->expr instanceof MethodCall) {
|
||||
if (! $secondExpression->expr instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$firstMethodCallMatch = $this->matchMethodCall($firstStmt->expr);
|
||||
$firstMethodCallMatch = $this->matchMethodCall($firstExpression->expr);
|
||||
if ($firstMethodCallMatch === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$secondMethodCallMatch = $this->matchMethodCall($expression->expr);
|
||||
$secondMethodCallMatch = $this->matchMethodCall($secondExpression->expr);
|
||||
if ($secondMethodCallMatch === null) {
|
||||
return false;
|
||||
}
|
||||
@ -179,8 +180,13 @@ CODE_SAMPLE
|
||||
++$i;
|
||||
}
|
||||
|
||||
$stmt = $classMethod->stmts[$fluentMethodCallIndex];
|
||||
if (! $stmt instanceof Expression) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
/** @var MethodCall $fluentMethodCall */
|
||||
$fluentMethodCall = $classMethod->stmts[$fluentMethodCallIndex]->expr;
|
||||
$fluentMethodCall = $stmt->expr;
|
||||
|
||||
// they are added in reversed direction
|
||||
$methodCallsToAdd = array_reverse($methodCallsToAdd);
|
||||
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Rector\Generic\Rector\Class_;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
@ -91,7 +90,7 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! Strings::endsWith((string) $node->name, 'Controller')) {
|
||||
if (! $this->isName($node, '*Controller')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -215,10 +215,7 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
|
||||
$name = $this->getName($property);
|
||||
if ($name === null) {
|
||||
return null;
|
||||
}
|
||||
$propertyName = $this->getName($property);
|
||||
|
||||
/** @var PhpDocInfo $phpDocInfo */
|
||||
$phpDocInfo = $property->getAttribute(AttributeKey::PHP_DOC_INFO);
|
||||
@ -230,7 +227,7 @@ CODE_SAMPLE
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$this->addConstructorDependencyToClass($classLike, $type, $name);
|
||||
$this->addConstructorDependencyToClass($classLike, $type, $propertyName);
|
||||
|
||||
return $property;
|
||||
}
|
||||
|
@ -122,11 +122,7 @@ CODE_SAMPLE
|
||||
return $this->isName($node->name, $methodName);
|
||||
}
|
||||
|
||||
if ($node instanceof ClassMethod) {
|
||||
return $this->isName($node->name, $methodName);
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this->isName($node->name, $methodName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,27 +56,27 @@ final class SingletonClassMethodAnalyzer
|
||||
*/
|
||||
public function matchStaticPropertyFetch(ClassMethod $classMethod): ?StaticPropertyFetch
|
||||
{
|
||||
if (count((array) $classMethod->stmts) !== 2) {
|
||||
$stmts = (array) $classMethod->stmts;
|
||||
if (count($stmts) !== 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $classMethod->stmts[0] instanceof If_) {
|
||||
$firstStmt = $stmts[0] ?? null;
|
||||
if (! $firstStmt instanceof If_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var If_ $if */
|
||||
$if = $classMethod->stmts[0];
|
||||
$staticPropertyFetch = $this->matchStaticPropertyFetchInIfCond($if->cond);
|
||||
$staticPropertyFetch = $this->matchStaticPropertyFetchInIfCond($firstStmt->cond);
|
||||
|
||||
if (count((array) $if->stmts) !== 1) {
|
||||
if (count((array) $firstStmt->stmts) !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $if->stmts[0] instanceof Expression) {
|
||||
if (! $firstStmt->stmts[0] instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$stmt = $if->stmts[0]->expr;
|
||||
$stmt = $firstStmt->stmts[0]->expr;
|
||||
|
||||
// create self and assign to static property
|
||||
if (! $stmt instanceof Assign) {
|
||||
|
@ -245,6 +245,7 @@ CODE_SAMPLE
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var MethodCall|PropertyFetch $node */
|
||||
if (! $node->var instanceof Variable) {
|
||||
return false;
|
||||
}
|
||||
|
@ -186,7 +186,11 @@ CODE_SAMPLE
|
||||
return $this->isObjectType($node->expr, 'mysqli');
|
||||
});
|
||||
|
||||
return $connectionAssign !== null ? $connectionAssign->var : null;
|
||||
if (! $connectionAssign instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $connectionAssign->var;
|
||||
}
|
||||
|
||||
private function removeExistingConnectionParameter(FuncCall $funcCall): void
|
||||
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Naming\Contract\Guard;
|
||||
|
||||
interface ConflictingGuardAwareInterface
|
||||
{
|
||||
public function provideGuard(): ConflictingGuardInterface;
|
||||
}
|
@ -6,7 +6,7 @@ namespace Rector\Naming\Contract\Guard;
|
||||
|
||||
use Rector\Naming\Contract\RenameValueObjectInterface;
|
||||
|
||||
interface GuardInterface
|
||||
interface ConflictingGuardInterface
|
||||
{
|
||||
public function check(RenameValueObjectInterface $renameValueObject): bool;
|
||||
}
|
@ -4,13 +4,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Rector\Naming\Contract\RenameGuard;
|
||||
|
||||
use Rector\Naming\Contract\Guard\GuardInterface;
|
||||
use Rector\Naming\Contract\Guard\ConflictingGuardInterface;
|
||||
use Rector\Naming\Contract\RenameValueObjectInterface;
|
||||
|
||||
interface RenameGuardInterface
|
||||
{
|
||||
/**
|
||||
* @param GuardInterface[] $guards
|
||||
* @param ConflictingGuardInterface[] $guards
|
||||
*/
|
||||
public function shouldSkip(RenameValueObjectInterface $renameValueObject, array $guards): bool;
|
||||
}
|
||||
|
@ -7,13 +7,13 @@ namespace Rector\Naming\Guard;
|
||||
use DateTimeInterface;
|
||||
use Nette\Utils\Strings;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use Rector\Naming\Contract\Guard\GuardInterface;
|
||||
use Rector\Naming\Contract\Guard\ConflictingGuardInterface;
|
||||
use Rector\Naming\Contract\RenameValueObjectInterface;
|
||||
use Rector\Naming\ValueObject\PropertyRename;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper;
|
||||
|
||||
final class DateTimeAtNamingConventionGuard implements GuardInterface
|
||||
final class DateTimeAtNamingConventionGuard implements ConflictingGuardInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
|
@ -4,11 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Rector\Naming\Guard;
|
||||
|
||||
use Rector\Naming\Contract\Guard\GuardInterface;
|
||||
use Rector\Naming\Contract\Guard\ConflictingGuardInterface;
|
||||
use Rector\Naming\Contract\RenameValueObjectInterface;
|
||||
use Rector\Naming\ValueObject\PropertyRename;
|
||||
|
||||
final class HasMagicGetSetGuard implements GuardInterface
|
||||
final class HasMagicGetSetGuard implements ConflictingGuardInterface
|
||||
{
|
||||
/**
|
||||
* @param PropertyRename $renameValueObject
|
||||
|
@ -4,11 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Rector\Naming\Guard;
|
||||
|
||||
use Rector\Naming\Contract\Guard\GuardInterface;
|
||||
use Rector\Naming\Contract\Guard\ConflictingGuardInterface;
|
||||
use Rector\Naming\Contract\RenameValueObjectInterface;
|
||||
use Rector\Naming\ValueObject\PropertyRename;
|
||||
|
||||
final class NotPrivatePropertyGuard implements GuardInterface
|
||||
final class NotPrivatePropertyGuard implements ConflictingGuardInterface
|
||||
{
|
||||
/**
|
||||
* @param PropertyRename $renameValueObject
|
||||
|
@ -7,13 +7,13 @@ namespace Rector\Naming\Guard\PropertyConflictingNameGuard;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use Rector\Naming\Contract\ExpectedNameResolver\ExpectedNameResolverInterface;
|
||||
use Rector\Naming\Contract\Guard\GuardInterface;
|
||||
use Rector\Naming\Contract\Guard\ConflictingGuardInterface;
|
||||
use Rector\Naming\Contract\RenameValueObjectInterface;
|
||||
use Rector\Naming\PhpArray\ArrayFilter;
|
||||
use Rector\Naming\ValueObject\PropertyRename;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
|
||||
abstract class AbstractPropertyConflictingNameGuard implements GuardInterface
|
||||
abstract class AbstractPropertyConflictingNameGuard implements ConflictingGuardInterface
|
||||
{
|
||||
/**
|
||||
* @var ExpectedNameResolverInterface
|
||||
|
@ -5,12 +5,12 @@ declare(strict_types=1);
|
||||
namespace Rector\Naming\Guard;
|
||||
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
use Rector\Naming\Contract\Guard\GuardInterface;
|
||||
use Rector\Naming\Contract\Guard\ConflictingGuardInterface;
|
||||
use Rector\Naming\Contract\RenameValueObjectInterface;
|
||||
use Rector\Naming\ValueObject\PropertyRename;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
|
||||
final class RamseyUuidInterfaceGuard implements GuardInterface
|
||||
final class RamseyUuidInterfaceGuard implements ConflictingGuardInterface
|
||||
{
|
||||
/**
|
||||
* @var NodeTypeResolver
|
||||
|
@ -59,14 +59,11 @@ abstract class AbstractMatcher implements MatcherInterface
|
||||
return new VariableAndCallForeach($variable, $call, $variableName, $functionLike);
|
||||
}
|
||||
|
||||
if ($node instanceof Assign) {
|
||||
return new VariableAndCallAssign($variable, $call, $node, $variableName, $functionLike);
|
||||
}
|
||||
|
||||
return null;
|
||||
return new VariableAndCallAssign($variable, $call, $node, $variableName, $functionLike);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Assign|Foreach_ $node
|
||||
* @return FuncCall|StaticCall|MethodCall|null
|
||||
*/
|
||||
protected function matchCall(Node $node): ?Node
|
||||
|
@ -133,10 +133,6 @@ final class ExpectedNameResolver
|
||||
}
|
||||
|
||||
$className = $this->nodeNameResolver->getName($new->class);
|
||||
if ($className === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$fullyQualifiedObjectType = new FullyQualifiedObjectType($className);
|
||||
|
||||
$expectedName = $this->propertyNaming->getExpectedNameFromType($fullyQualifiedObjectType);
|
||||
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Naming\ParamRenamer;
|
||||
|
||||
final class MatchTypeParamRenamer extends AbstractParamRenamer
|
||||
{
|
||||
}
|
@ -12,7 +12,7 @@ use Rector\Naming\Contract\RenameValueObjectInterface;
|
||||
use Rector\Naming\ValueObject\ParamRename;
|
||||
use Rector\Naming\VariableRenamer;
|
||||
|
||||
abstract class AbstractParamRenamer implements RenamerInterface
|
||||
final class ParamRenamer implements RenamerInterface
|
||||
{
|
||||
/**
|
||||
* @var VariableRenamer
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Naming\ParamRenamer;
|
||||
|
||||
final class UnderscoreCamelCaseParamRenamer extends AbstractParamRenamer
|
||||
{
|
||||
}
|
@ -11,7 +11,7 @@ use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\VarLikeIdentifier;
|
||||
use Rector\Core\PhpParser\NodeTraverser\CallableNodeTraverser;
|
||||
use Rector\Naming\Contract\Guard\GuardInterface;
|
||||
use Rector\Naming\Contract\Guard\ConflictingGuardInterface;
|
||||
use Rector\Naming\Contract\RenameGuard\RenameGuardInterface;
|
||||
use Rector\Naming\Contract\RenamerInterface;
|
||||
use Rector\Naming\Contract\RenameValueObjectInterface;
|
||||
@ -31,7 +31,7 @@ abstract class AbstractPropertyRenamer implements RenamerInterface
|
||||
protected $propertyRenameGuard;
|
||||
|
||||
/**
|
||||
* @var GuardInterface
|
||||
* @var ConflictingGuardInterface
|
||||
*/
|
||||
protected $conflictingPropertyNameGuard;
|
||||
|
||||
@ -92,7 +92,7 @@ abstract class AbstractPropertyRenamer implements RenamerInterface
|
||||
*/
|
||||
public function rename(RenameValueObjectInterface $renameValueObject): ?Node
|
||||
{
|
||||
if ($this->areNamesDifferent($renameValueObject)) {
|
||||
if (! $this->areNamesDifferent($renameValueObject)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -115,17 +115,19 @@ abstract class AbstractPropertyRenamer implements RenamerInterface
|
||||
|
||||
private function areNamesDifferent(PropertyRename $propertyRename): bool
|
||||
{
|
||||
return $propertyRename->getCurrentName() === $propertyRename->getExpectedName();
|
||||
return $propertyRename->getCurrentName() !== $propertyRename->getExpectedName();
|
||||
}
|
||||
|
||||
private function renamePropertyFetchesInClass(PropertyRename $propertyRename): void
|
||||
{
|
||||
// 1. replace property fetch rename in whole class
|
||||
$this->callableNodeTraverser->traverseNodesWithCallable(
|
||||
[$propertyRename->getClassLike()],
|
||||
$propertyRename->getClassLike(),
|
||||
function (Node $node) use ($propertyRename): ?Node {
|
||||
if ($this->nodeNameResolver->isLocalPropertyFetchNamed($node, $propertyRename->getCurrentName())) {
|
||||
/** @var PropertyFetch $node */
|
||||
if ($this->nodeNameResolver->isLocalPropertyFetchNamed(
|
||||
$node,
|
||||
$propertyRename->getCurrentName()
|
||||
) && $node instanceof PropertyFetch) {
|
||||
$node->name = new Identifier($propertyRename->getExpectedName());
|
||||
return $node;
|
||||
}
|
||||
@ -134,7 +136,10 @@ abstract class AbstractPropertyRenamer implements RenamerInterface
|
||||
$node,
|
||||
$propertyRename->getCurrentName()
|
||||
)) {
|
||||
/** @var StaticPropertyFetch $node */
|
||||
if (! $node instanceof StaticPropertyFetch) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$node->name = new VarLikeIdentifier($propertyRename->getExpectedName());
|
||||
return $node;
|
||||
}
|
||||
|
@ -178,9 +178,16 @@ CODE_SAMPLE
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var FuncCall|StaticCall|MethodCall $n */
|
||||
$passedNode = clone $n;
|
||||
|
||||
/** @var FuncCall|StaticCall|MethodCall $node */
|
||||
$usedNode = clone $node;
|
||||
|
||||
/** @var FuncCall|StaticCall|MethodCall $passedNode */
|
||||
$passedNode->args = [];
|
||||
|
||||
/** @var FuncCall|StaticCall|MethodCall $usedNode */
|
||||
$usedNode->args = [];
|
||||
|
||||
return $this->areNodesEqual($passedNode, $usedNode);
|
||||
|
@ -130,11 +130,12 @@ CODE_SAMPLE
|
||||
|
||||
private function matchGetterClassMethodReturnedExpr(ClassMethod $classMethod): ?Expr
|
||||
{
|
||||
if (count((array) $classMethod->stmts) !== 1) {
|
||||
$stmts = (array) $classMethod->stmts;
|
||||
if (count($stmts) !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$onlyStmt = $classMethod->stmts[0];
|
||||
$onlyStmt = $stmts[0] ?? null;
|
||||
if (! $onlyStmt instanceof Return_) {
|
||||
return null;
|
||||
}
|
||||
|
@ -130,11 +130,12 @@ CODE_SAMPLE
|
||||
|
||||
private function matchIsserClassMethodReturnedExpr(ClassMethod $classMethod): ?Expr
|
||||
{
|
||||
if (count((array) $classMethod->stmts) !== 1) {
|
||||
$stmts = (array) $classMethod->stmts;
|
||||
if (count($stmts) !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$onlyStmt = $classMethod->stmts[0];
|
||||
$onlyStmt = $stmts[0] ?? null;
|
||||
if (! $onlyStmt instanceof Return_) {
|
||||
return null;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Naming\ExpectedNameResolver\MatchParamTypeExpectedNameResolver;
|
||||
use Rector\Naming\Guard\BreakingVariableRenameGuard;
|
||||
use Rector\Naming\Naming\ExpectedNameResolver;
|
||||
use Rector\Naming\ParamRenamer\MatchTypeParamRenamer;
|
||||
use Rector\Naming\ParamRenamer\ParamRenamer;
|
||||
use Rector\Naming\ValueObjectFactory\ParamRenameFactory;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
@ -37,9 +37,9 @@ final class RenameParamToMatchTypeRector extends AbstractRector
|
||||
private $breakingVariableRenameGuard;
|
||||
|
||||
/**
|
||||
* @var MatchTypeParamRenamer
|
||||
* @var ParamRenamer
|
||||
*/
|
||||
private $matchTypeParamRenamer;
|
||||
private $paramRenamer;
|
||||
|
||||
/**
|
||||
* @var ParamRenameFactory
|
||||
@ -56,12 +56,12 @@ final class RenameParamToMatchTypeRector extends AbstractRector
|
||||
ExpectedNameResolver $expectedNameResolver,
|
||||
MatchParamTypeExpectedNameResolver $matchParamTypeExpectedNameResolver,
|
||||
ParamRenameFactory $paramRenameFactory,
|
||||
MatchTypeParamRenamer $matchTypeParamRenamer
|
||||
ParamRenamer $paramRenamer
|
||||
) {
|
||||
$this->expectedNameResolver = $expectedNameResolver;
|
||||
$this->breakingVariableRenameGuard = $breakingVariableRenameGuard;
|
||||
$this->paramRenameFactory = $paramRenameFactory;
|
||||
$this->matchTypeParamRenamer = $matchTypeParamRenamer;
|
||||
$this->paramRenamer = $paramRenamer;
|
||||
$this->matchParamTypeExpectedNameResolver = $matchParamTypeExpectedNameResolver;
|
||||
}
|
||||
|
||||
@ -121,8 +121,8 @@ CODE_SAMPLE
|
||||
if ($paramRename === null) {
|
||||
continue;
|
||||
}
|
||||
$matchTypeParamRenamerRename = $this->matchTypeParamRenamer->rename($paramRename);
|
||||
|
||||
$matchTypeParamRenamerRename = $this->paramRenamer->rename($paramRename);
|
||||
if ($matchTypeParamRenamerRename === null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -88,12 +88,8 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$nodeName = $this->getName($node);
|
||||
if ($nodeName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! Strings::contains($nodeName, '_')) {
|
||||
$propertyName = $this->getName($node);
|
||||
if (! Strings::contains($propertyName, '_')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -117,22 +117,21 @@ CODE_SAMPLE
|
||||
|
||||
private function isFoundInParentNode(Variable $variable): bool
|
||||
{
|
||||
$parentNode = $variable->getAttribute(AttributeKey::PARENT_NODE);
|
||||
while ($parentNode) {
|
||||
/** @var ClassMethod|Function_ $parentNode */
|
||||
$parentNode = $parentNode->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof ClassMethod || $parentNode instanceof Function_) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/** @var ClassMethod|Function_|null $classMethodOrFunction */
|
||||
$classMethodOrFunction = $this->betterNodeFinder->findFirstParentInstanceOf(
|
||||
$variable,
|
||||
[ClassMethod::class, Function_::class]
|
||||
);
|
||||
|
||||
if ($parentNode === null) {
|
||||
if ($classMethodOrFunction === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$params = $parentNode->getParams();
|
||||
/** @var Param[] $params */
|
||||
$params = (array) $classMethodOrFunction->getParams();
|
||||
|
||||
foreach ($params as $param) {
|
||||
if ($param->var->name === $variable->name) {
|
||||
if ($this->areNamesEqual($param->var, $variable)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ use Rector\Core\Php\ReservedKeywordAnalyzer;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Util\StaticRectorStrings;
|
||||
use Rector\Naming\ExpectedNameResolver\UnderscoreCamelCaseExpectedNameResolver;
|
||||
use Rector\Naming\ParamRenamer\UnderscoreCamelCaseParamRenamer;
|
||||
use Rector\Naming\ParamRenamer\ParamRenamer;
|
||||
use Rector\Naming\ValueObjectFactory\ParamRenameFactory;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
@ -39,20 +39,20 @@ final class UnderscoreToCamelCaseVariableNameRector extends AbstractRector
|
||||
private $underscoreCamelCaseExpectedNameResolver;
|
||||
|
||||
/**
|
||||
* @var UnderscoreCamelCaseParamRenamer
|
||||
* @var ParamRenamer
|
||||
*/
|
||||
private $underscoreCamelCaseParamRenamer;
|
||||
private $paramRenamer;
|
||||
|
||||
public function __construct(
|
||||
ReservedKeywordAnalyzer $reservedKeywordAnalyzer,
|
||||
ParamRenameFactory $paramRenameFactory,
|
||||
UnderscoreCamelCaseParamRenamer $underscoreCamelCaseParamRenamer,
|
||||
ParamRenamer $underscoreCamelCaseParamRenamer,
|
||||
UnderscoreCamelCaseExpectedNameResolver $underscoreCamelCaseExpectedNameResolver
|
||||
) {
|
||||
$this->reservedKeywordAnalyzer = $reservedKeywordAnalyzer;
|
||||
$this->paramRenameFactory = $paramRenameFactory;
|
||||
$this->underscoreCamelCaseExpectedNameResolver = $underscoreCamelCaseExpectedNameResolver;
|
||||
$this->underscoreCamelCaseParamRenamer = $underscoreCamelCaseParamRenamer;
|
||||
$this->paramRenamer = $underscoreCamelCaseParamRenamer;
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
@ -113,10 +113,9 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Param $parentNode */
|
||||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof Param) {
|
||||
return $this->renameParam($parentNode);
|
||||
$parent = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parent instanceof Param) {
|
||||
return $this->renameParam($parent);
|
||||
}
|
||||
|
||||
$node->name = $camelCaseName;
|
||||
@ -131,7 +130,7 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
|
||||
$renamedParam = $this->underscoreCamelCaseParamRenamer->rename($paramRename);
|
||||
$renamedParam = $this->paramRenamer->rename($paramRename);
|
||||
if ($renamedParam === null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -4,14 +4,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace Rector\Naming\RenameGuard;
|
||||
|
||||
use Rector\Naming\Contract\Guard\GuardInterface;
|
||||
use Rector\Naming\Contract\Guard\ConflictingGuardInterface;
|
||||
use Rector\Naming\Contract\RenameGuard\RenameGuardInterface;
|
||||
use Rector\Naming\Contract\RenameValueObjectInterface;
|
||||
|
||||
final class PropertyRenameGuard implements RenameGuardInterface
|
||||
{
|
||||
/**
|
||||
* @param GuardInterface[] $guards
|
||||
* @param ConflictingGuardInterface[] $guards
|
||||
*/
|
||||
public function shouldSkip(RenameValueObjectInterface $renameValueObject, array $guards): bool
|
||||
{
|
||||
|
@ -190,13 +190,17 @@ final class EventAndListenerTreeProvider
|
||||
/** @var Class_ $eventClass */
|
||||
$eventClass = $eventClassInNamespace->stmts[0];
|
||||
$getterMethodBlueprints = [];
|
||||
|
||||
foreach ($eventClass->getMethods() as $classMethod) {
|
||||
if (! $this->nodeNameResolver->isName($classMethod, 'get*')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$stmts = (array) $classMethod->stmts;
|
||||
|
||||
/** @var Return_ $return */
|
||||
$return = $classMethod->stmts[0];
|
||||
$return = $stmts[0];
|
||||
|
||||
/** @var PropertyFetch $propertyFetch */
|
||||
$propertyFetch = $return->expr;
|
||||
|
||||
|
@ -21,6 +21,7 @@ use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\NetteKdyby\BlueprintFactory\VariableWithTypesFactory;
|
||||
use Rector\NetteKdyby\ValueObject\VariableWithType;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
|
||||
/**
|
||||
* @todo decouple to generic object factory for better re-use, e.g. this is just value object pattern
|
||||
@ -41,15 +42,21 @@ final class EventValueObjectClassFactory
|
||||
* @var NodeFactory
|
||||
*/
|
||||
private $nodeFactory;
|
||||
/**
|
||||
* @var NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
|
||||
public function __construct(
|
||||
ClassNaming $classNaming,
|
||||
NodeFactory $nodeFactory,
|
||||
NodeNameResolver $nodeNameResolver,
|
||||
VariableWithTypesFactory $variableWithTypesFactory
|
||||
) {
|
||||
$this->classNaming = $classNaming;
|
||||
$this->variableWithTypesFactory = $variableWithTypesFactory;
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,11 +137,10 @@ final class EventValueObjectClassFactory
|
||||
{
|
||||
$usedVariableNames = [];
|
||||
|
||||
$className = $classBuilder->getNode()
|
||||
->name;
|
||||
|
||||
foreach ($variablesWithTypes as $variablesWithType) {
|
||||
if (in_array($variablesWithType->getName(), $usedVariableNames, true)) {
|
||||
$className = $this->nodeNameResolver->getName($classBuilder->getNode());
|
||||
|
||||
$message = sprintf(
|
||||
'Variable "$%s" is duplicated in to be created "%s" class',
|
||||
$variablesWithType->getName(),
|
||||
|
@ -84,6 +84,10 @@ final class ListeningMethodsCollector
|
||||
return;
|
||||
}
|
||||
|
||||
if ($node->key === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$eventClass = $this->valueResolver->getValue($node->key);
|
||||
|
||||
if ($type === self::EVENT_TYPE_CONTRIBUTTE) {
|
||||
@ -182,10 +186,6 @@ final class ListeningMethodsCollector
|
||||
);
|
||||
}
|
||||
|
||||
if ($eventClass === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($classMethod === null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -152,10 +152,6 @@ CODE_SAMPLE
|
||||
$eventClassName = $this->eventClassNaming->createEventClassNameFromClassPropertyReference(
|
||||
$eventPropertyReferenceName
|
||||
);
|
||||
if ($eventClassName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$node->key = $this->createClassConstantReference($eventClassName);
|
||||
});
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ namespace Rector\NetteKdyby\Rector\MethodCall;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Identifier;
|
||||
@ -114,11 +115,7 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->isObjectType($node->var, 'Kdyby\Events\EventManager')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isName($node->name, 'dispatchEvent')) {
|
||||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -134,21 +131,10 @@ CODE_SAMPLE
|
||||
$classAndStaticProperty
|
||||
);
|
||||
|
||||
$args = [];
|
||||
if ($oldArgs[1]->value instanceof New_) {
|
||||
/** @var New_ $new */
|
||||
$new = $oldArgs[1]->value;
|
||||
$args = $this->createNewArgs($oldArgs);
|
||||
|
||||
$array = $new->args[0]->value;
|
||||
if ($array instanceof Array_) {
|
||||
foreach ($array->items as $arrayItem) {
|
||||
$args[] = new Arg($arrayItem->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$class = new New_(new FullyQualified($eventClassName), $args);
|
||||
$node->args[] = new Arg($class);
|
||||
$new = new New_(new FullyQualified($eventClassName), $args);
|
||||
$node->args[] = new Arg($new);
|
||||
|
||||
// 3. create new event class with args
|
||||
$eventClassInNamespace = $this->eventValueObjectClassFactory->create($eventClassName, $args);
|
||||
@ -168,4 +154,41 @@ CODE_SAMPLE
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function shouldSkip(MethodCall $methodCall): bool
|
||||
{
|
||||
if (! $this->isObjectType($methodCall->var, 'Kdyby\Events\EventManager')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ! $this->isName($methodCall->name, 'dispatchEvent');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Arg[] $oldArgs
|
||||
* @return Arg[]
|
||||
*/
|
||||
private function createNewArgs(array $oldArgs): array
|
||||
{
|
||||
$args = [];
|
||||
|
||||
if ($oldArgs[1]->value instanceof New_) {
|
||||
/** @var New_ $new */
|
||||
$new = $oldArgs[1]->value;
|
||||
|
||||
$array = $new->args[0]->value;
|
||||
if (! $array instanceof Array_) {
|
||||
return [];
|
||||
}
|
||||
foreach ($array->items as $arrayItem) {
|
||||
if (! $arrayItem instanceof ArrayItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$args[] = new Arg($arrayItem->value);
|
||||
}
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ CODE_SAMPLE
|
||||
{
|
||||
// look for <...>[] = IRoute<Type>
|
||||
|
||||
return $this->betterNodeFinder->find($classMethod->stmts, function (Node $node): bool {
|
||||
return $this->betterNodeFinder->find((array) $classMethod->stmts, function (Node $node): bool {
|
||||
if (! $node instanceof Assign) {
|
||||
return false;
|
||||
}
|
||||
|
@ -101,25 +101,15 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if ($this->isAnonymousClass($node)) {
|
||||
if ($this->shouldSkipClass($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// skip presenter
|
||||
if ($this->isName($node, '*Presenter')) {
|
||||
return null;
|
||||
}
|
||||
$shortClassName = $this->getShortName($node);
|
||||
$shortClassName = $this->removeSuffix($shortClassName, 'Control');
|
||||
$shortClassName .= 'Controller';
|
||||
|
||||
if (! $this->isObjectType($node, 'Nette\Application\UI\Control')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$className = (string) $node->name;
|
||||
|
||||
$className = $this->removeSuffix($className, 'Control');
|
||||
$className .= 'Controller';
|
||||
|
||||
$node->name = new Identifier($className);
|
||||
$node->name = new Identifier($shortClassName);
|
||||
$node->extends = new FullyQualified(AbstractController::class);
|
||||
|
||||
$classMethod = $node->getMethod('render');
|
||||
@ -130,6 +120,20 @@ CODE_SAMPLE
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function shouldSkipClass(Class_ $class): bool
|
||||
{
|
||||
if ($this->isAnonymousClass($class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// skip presenter
|
||||
if ($this->isName($class, '*Presenter')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ! $this->isObjectType($class, 'Nette\Application\UI\Control');
|
||||
}
|
||||
|
||||
private function removeSuffix(string $content, string $suffix): string
|
||||
{
|
||||
if (! Strings::endsWith($content, $suffix)) {
|
||||
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Nette\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
|
||||
/**
|
||||
* @see https://www.tomasvotruba.cz/blog/2019/02/07/what-i-learned-by-using-thecodingmachine-safe/#is-there-a-better-way
|
||||
*
|
||||
* @see \Rector\Nette\Tests\Rector\FuncCall\PregMatchFunctionToNetteUtilsStringsRector\PregMatchFunctionToNetteUtilsStringsRectorTest
|
||||
*/
|
||||
abstract class AbstractPregToNetteUtilsStringsRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @param array<string, string> $functionRenameMap
|
||||
*/
|
||||
protected function matchFuncCallRenameToMethod(FuncCall $funcCall, array $functionRenameMap): ?string
|
||||
{
|
||||
$oldFunctionNames = array_keys($functionRenameMap);
|
||||
if (! $this->isNames($funcCall, $oldFunctionNames)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$currentFunctionName = $this->getName($funcCall);
|
||||
return $functionRenameMap[$currentFunctionName];
|
||||
}
|
||||
}
|
@ -18,7 +18,6 @@ use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
@ -28,7 +27,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
*
|
||||
* @see \Rector\Nette\Tests\Rector\FuncCall\PregFunctionToNetteUtilsStringsRector\PregFunctionToNetteUtilsStringsRectorTest
|
||||
*/
|
||||
final class PregFunctionToNetteUtilsStringsRector extends AbstractRector
|
||||
final class PregFunctionToNetteUtilsStringsRector extends AbstractPregToNetteUtilsStringsRector
|
||||
{
|
||||
/**
|
||||
* @var array<string, string>
|
||||
@ -125,18 +124,16 @@ CODE_SAMPLE
|
||||
*/
|
||||
private function refactorFuncCall(FuncCall $funcCall): ?Expr
|
||||
{
|
||||
$oldFunctionNames = array_keys(self::FUNCTION_NAME_TO_METHOD_NAME);
|
||||
if (! $this->isNames($funcCall, $oldFunctionNames)) {
|
||||
$methodName = $this->matchFuncCallRenameToMethod($funcCall, self::FUNCTION_NAME_TO_METHOD_NAME);
|
||||
if ($methodName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$currentFunctionName = $this->getName($funcCall);
|
||||
|
||||
$methodName = self::FUNCTION_NAME_TO_METHOD_NAME[$currentFunctionName];
|
||||
$matchStaticCall = $this->createMatchStaticCall($funcCall, $methodName);
|
||||
|
||||
// skip assigns, might be used with different return value
|
||||
$parentNode = $funcCall->getAttribute(AttributeKey::PARENT_NODE);
|
||||
|
||||
if ($parentNode instanceof Assign) {
|
||||
if ($methodName === 'split') {
|
||||
return $this->processSplit($funcCall, $matchStaticCall);
|
||||
@ -149,6 +146,8 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
|
||||
$currentFunctionName = $this->getName($funcCall);
|
||||
|
||||
// assign
|
||||
if (isset($funcCall->args[2]) && $currentFunctionName !== 'preg_replace') {
|
||||
return new Assign($funcCall->args[2]->value, $matchStaticCall);
|
||||
|
@ -17,7 +17,6 @@ use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
@ -27,7 +26,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
*
|
||||
* @see \Rector\Nette\Tests\Rector\FuncCall\PregMatchFunctionToNetteUtilsStringsRector\PregMatchFunctionToNetteUtilsStringsRectorTest
|
||||
*/
|
||||
final class PregMatchFunctionToNetteUtilsStringsRector extends AbstractRector
|
||||
final class PregMatchFunctionToNetteUtilsStringsRector extends AbstractPregToNetteUtilsStringsRector
|
||||
{
|
||||
/**
|
||||
* @var array<string, string>
|
||||
@ -117,14 +116,11 @@ CODE_SAMPLE
|
||||
*/
|
||||
private function refactorFuncCall(FuncCall $funcCall): ?Expr
|
||||
{
|
||||
$oldFunctionNames = array_keys(self::FUNCTION_NAME_TO_METHOD_NAME);
|
||||
if (! $this->isNames($funcCall, $oldFunctionNames)) {
|
||||
$methodName = $this->matchFuncCallRenameToMethod($funcCall, self::FUNCTION_NAME_TO_METHOD_NAME);
|
||||
if ($methodName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$currentFunctionName = $this->getName($funcCall);
|
||||
|
||||
$methodName = self::FUNCTION_NAME_TO_METHOD_NAME[$currentFunctionName];
|
||||
$matchStaticCall = $this->createMatchStaticCall($funcCall, $methodName);
|
||||
|
||||
// skip assigns, might be used with different return value
|
||||
|
@ -12,6 +12,7 @@ use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use Rector\CodingStyle\Naming\ClassNaming;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Util\StaticRectorStrings;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
@ -34,35 +35,39 @@ final class PhpSpecRenaming
|
||||
* @var NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @var ClassNaming
|
||||
*/
|
||||
private $classNaming;
|
||||
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, StringFormatConverter $stringFormatConverter)
|
||||
{
|
||||
public function __construct(
|
||||
NodeNameResolver $nodeNameResolver,
|
||||
StringFormatConverter $stringFormatConverter,
|
||||
ClassNaming $classNaming
|
||||
) {
|
||||
$this->stringFormatConverter = $stringFormatConverter;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->classNaming = $classNaming;
|
||||
}
|
||||
|
||||
public function renameMethod(ClassMethod $classMethod): void
|
||||
{
|
||||
$name = $this->nodeNameResolver->getName($classMethod);
|
||||
if ($name === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($classMethod->isPrivate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$name = $this->removeNamePrefixes($name);
|
||||
$classMethodName = $this->nodeNameResolver->getName($classMethod);
|
||||
$classMethodName = $this->removeNamePrefixes($classMethodName);
|
||||
|
||||
// from PhpSpec to PHPUnit method naming convention
|
||||
$name = $this->stringFormatConverter->underscoreAndHyphenToCamelCase($name);
|
||||
$classMethodName = $this->stringFormatConverter->underscoreAndHyphenToCamelCase($classMethodName);
|
||||
|
||||
// add "test", so PHPUnit runs the method
|
||||
if (! Strings::startsWith($name, 'test')) {
|
||||
$name = 'test' . ucfirst($name);
|
||||
if (! Strings::startsWith($classMethodName, 'test')) {
|
||||
$classMethodName = 'test' . ucfirst($classMethodName);
|
||||
}
|
||||
|
||||
$classMethod->name = new Identifier($name);
|
||||
$classMethod->name = new Identifier($classMethodName);
|
||||
}
|
||||
|
||||
public function renameExtends(Class_ $class): void
|
||||
@ -72,26 +77,32 @@ final class PhpSpecRenaming
|
||||
|
||||
public function renameNamespace(Class_ $class): void
|
||||
{
|
||||
/** @var Namespace_ $namespace */
|
||||
/** @var Namespace_|null $namespace */
|
||||
$namespace = $class->getAttribute(AttributeKey::NAMESPACE_NODE);
|
||||
if ($namespace->name === null) {
|
||||
if ($namespace === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$newNamespaceName = StaticRectorStrings::removePrefixes($namespace->name->toString(), ['spec\\']);
|
||||
$namespaceName = $this->nodeNameResolver->getName($namespace);
|
||||
if ($namespaceName === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$newNamespaceName = StaticRectorStrings::removePrefixes($namespaceName, ['spec\\']);
|
||||
|
||||
$namespace->name = new Name('Tests\\' . $newNamespaceName);
|
||||
}
|
||||
|
||||
public function renameClass(Class_ $class): void
|
||||
{
|
||||
$classShortName = $this->classNaming->getShortName($class);
|
||||
// anonymous class?
|
||||
if ($class->name === null) {
|
||||
if ($classShortName === '') {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
// 2. change class name
|
||||
$newClassName = StaticRectorStrings::removeSuffixes($class->name->toString(), [self::SPEC]);
|
||||
$newClassName = StaticRectorStrings::removeSuffixes($classShortName, [self::SPEC]);
|
||||
$newTestClassName = $newClassName . 'Test';
|
||||
|
||||
$class->name = new Identifier($newTestClassName);
|
||||
@ -104,7 +115,8 @@ final class PhpSpecRenaming
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$bareClassName = StaticRectorStrings::removeSuffixes($class->name->toString(), [self::SPEC, 'Test']);
|
||||
$shortClassName = $this->classNaming->getShortName($class);
|
||||
$bareClassName = StaticRectorStrings::removeSuffixes($shortClassName, [self::SPEC, 'Test']);
|
||||
|
||||
return lcfirst($bareClassName);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
@ -156,6 +157,9 @@ final class PhpSpecClassToPHPUnitClassRector extends AbstractPhpSpecToPHPUnitRec
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Stmt[] $stmts
|
||||
*/
|
||||
private function resolveFirstNonExpressionStmt(array $stmts): ?Node
|
||||
{
|
||||
if (! isset($stmts[0])) {
|
||||
|
@ -9,6 +9,7 @@ use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Clone_;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
@ -208,6 +209,7 @@ final class PhpSpecPromisesToPHPUnitAssertRector extends AbstractPhpSpecToPHPUni
|
||||
if (isset($methodCall->args[1]) && $methodCall->args[1]->value instanceof Array_) {
|
||||
/** @var Array_ $array */
|
||||
$array = $methodCall->args[1]->value;
|
||||
|
||||
if (isset($array->items[0])) {
|
||||
$thisObjectPropertyMethodCall->args[] = new Arg($array->items[0]->value);
|
||||
}
|
||||
@ -356,6 +358,10 @@ final class PhpSpecPromisesToPHPUnitAssertRector extends AbstractPhpSpecToPHPUni
|
||||
/** @var Array_ $array */
|
||||
$array = $methodCall->args[1]->value;
|
||||
foreach ($array->items as $arrayItem) {
|
||||
if (! $arrayItem instanceof ArrayItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$staticCall->args[] = new Arg($arrayItem->value);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ namespace Rector\Php52\Rector\Switch_;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Break_;
|
||||
use PhpParser\Node\Stmt\Continue_;
|
||||
use PhpParser\Node\Stmt\Switch_;
|
||||
@ -75,16 +76,18 @@ CODE_SAMPLE
|
||||
{
|
||||
foreach ($node->cases as $case) {
|
||||
foreach ($case->stmts as $key => $caseStmt) {
|
||||
if ($caseStmt instanceof Continue_) {
|
||||
$case->stmts[$key] = $this->processContinueStatement($caseStmt);
|
||||
if (! $caseStmt instanceof Continue_) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$case->stmts[$key] = $this->processContinueStatement($caseStmt);
|
||||
}
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function processContinueStatement(Continue_ $continue): Node
|
||||
private function processContinueStatement(Continue_ $continue): Stmt
|
||||
{
|
||||
if ($continue->num === null) {
|
||||
return new Break_();
|
||||
@ -101,7 +104,7 @@ CODE_SAMPLE
|
||||
return $continue;
|
||||
}
|
||||
|
||||
private function processVariableNum(Continue_ $continue, Variable $numVariable): Node
|
||||
private function processVariableNum(Continue_ $continue, Variable $numVariable): Stmt
|
||||
{
|
||||
$staticType = $this->getStaticType($numVariable);
|
||||
|
||||
|
@ -9,6 +9,7 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
@ -130,12 +131,12 @@ CODE_SAMPLE
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Node[] $nodes
|
||||
* @return Node[]
|
||||
* @param Stmt[] $stmts
|
||||
* @return Stmt[]
|
||||
*/
|
||||
private function refactorStmts(array $nodes): array
|
||||
private function refactorStmts(array $stmts): array
|
||||
{
|
||||
$this->traverseNodesWithCallable($nodes, function (Node $node): ?Node {
|
||||
$this->traverseNodesWithCallable($stmts, function (Node $node): ?Node {
|
||||
if (! $this->isInstancesOf($node, [Name::class, Identifier::class, Property::class, FunctionLike::class])) {
|
||||
return null;
|
||||
}
|
||||
@ -152,7 +153,7 @@ CODE_SAMPLE
|
||||
return null;
|
||||
});
|
||||
|
||||
return $nodes;
|
||||
return $stmts;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -230,17 +230,11 @@ CODE_SAMPLE
|
||||
|
||||
private function isInsideLoopStmts(Node $node): bool
|
||||
{
|
||||
$parent = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
|
||||
while ($parent) {
|
||||
if ($parent instanceof For_ || $parent instanceof While_ || $parent instanceof Foreach_ || $parent instanceof Do_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$parent = $parent->getAttribute(AttributeKey::PARENT_NODE);
|
||||
}
|
||||
|
||||
return false;
|
||||
$loopNode = $this->betterNodeFinder->findFirstParentInstanceOf(
|
||||
$node,
|
||||
[For_::class, While_::class, Foreach_::class, Do_::class]
|
||||
);
|
||||
return (bool) $loopNode;
|
||||
}
|
||||
|
||||
private function mayBeArrayDimFetch(Node $node): Node
|
||||
|
@ -239,7 +239,7 @@ CODE_SAMPLE
|
||||
{
|
||||
$class->implements[] = new FullyQualified(self::EVENT_SUBSCRIBER_INTERFACE);
|
||||
|
||||
$classShortName = $this->getShortName($class->name);
|
||||
$classShortName = $this->getShortName($class);
|
||||
|
||||
// remove suffix
|
||||
$classShortName = Strings::replace($classShortName, self::LISTENER_MATCH_REGEX, '$1');
|
||||
|
@ -13,6 +13,7 @@ use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use Rector\CodingStyle\Naming\ClassNaming;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
@ -66,7 +67,7 @@ trait NameResolverTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|Name|Identifier $name
|
||||
* @param string|Name|Identifier|ClassLike $name
|
||||
*/
|
||||
protected function getShortName($name): string
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user