Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ include/require to absolute path. This Rector might introduce backwards incompat

### AndAssignsToSeparateLinesRector

Split 2 assigns ands to separate line
Split 2 assigns and to separate line

- class: [`Rector\CodeQuality\Rector\LogicalAnd\AndAssignsToSeparateLinesRector`](../rules/CodeQuality/Rector/LogicalAnd/AndAssignsToSeparateLinesRector.php)

Expand Down Expand Up @@ -1598,9 +1598,9 @@ Use ===/!== over ==/!=, it values have the same type
public function run(int $firstValue, int $secondValue)
{
- $isSame = $firstValue == $secondValue;
- $isDiffernt = $firstValue != $secondValue;
- $isDifferent = $firstValue != $secondValue;
+ $isSame = $firstValue === $secondValue;
+ $isDiffernt = $firstValue !== $secondValue;
+ $isDifferent = $firstValue !== $secondValue;
}
}
```
Expand Down Expand Up @@ -2083,7 +2083,7 @@ Makes array_search search for identical elements

<br>

### SymplifyQuoteEscapeRector
### SimplifyQuoteEscapeRector

Prefer quote that are not inside the string

Expand Down Expand Up @@ -2279,7 +2279,7 @@ Remove (string) casting when it comes to concat, that does this by default
- class: [`Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector`](../rules/DeadCode/Rector/Concat/RemoveConcatAutocastRector.php)

```diff
class SomeConcatingClass
class SomeConcatenatingClass
{
public function run($value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function refactor(Node $node) : ?Node
}
return $node;
}
private function refactorThrow(Throw_ $throw, Variable $catchedThrowableVariable) : ?int
private function refactorThrow(Throw_ $throw, Variable $caughtThrowableVariable) : ?int
{
if (!$throw->expr instanceof New_) {
return null;
Expand All @@ -123,23 +123,23 @@ private function refactorThrow(Throw_ $throw, Variable $catchedThrowableVariable
$shouldUseNamedArguments = $messageArgument instanceof Arg && $messageArgument->name instanceof Identifier;
if (!isset($new->args[0])) {
// get previous message
$getMessageMethodCall = new MethodCall($catchedThrowableVariable, 'getMessage');
$getMessageMethodCall = new MethodCall($caughtThrowableVariable, 'getMessage');
$new->args[0] = new Arg($getMessageMethodCall);
} elseif ($new->args[0] instanceof Arg && $new->args[0]->name instanceof Identifier && $new->args[0]->name->toString() === 'previous' && $this->nodeComparator->areNodesEqual($new->args[0]->value, $catchedThrowableVariable)) {
} elseif ($new->args[0] instanceof Arg && $new->args[0]->name instanceof Identifier && $new->args[0]->name->toString() === 'previous' && $this->nodeComparator->areNodesEqual($new->args[0]->value, $caughtThrowableVariable)) {
$new->args[0]->name->name = 'message';
$new->args[0]->value = new MethodCall($catchedThrowableVariable, 'getMessage');
$new->args[0]->value = new MethodCall($caughtThrowableVariable, 'getMessage');
}
if (!isset($new->getArgs()[1])) {
// get previous code
$new->args[1] = new Arg(new MethodCall($catchedThrowableVariable, 'getCode'), \false, \false, [], $shouldUseNamedArguments ? new Identifier('code') : null);
$new->args[1] = new Arg(new MethodCall($caughtThrowableVariable, 'getCode'), \false, \false, [], $shouldUseNamedArguments ? new Identifier('code') : null);
}
/** @var Arg $arg1 */
$arg1 = $new->args[1];
if ($arg1->name instanceof Identifier && $arg1->name->toString() === 'previous') {
$new->args[1] = new Arg(new MethodCall($catchedThrowableVariable, 'getCode'), \false, \false, [], $shouldUseNamedArguments ? new Identifier('code') : null);
$new->args[1] = new Arg(new MethodCall($caughtThrowableVariable, 'getCode'), \false, \false, [], $shouldUseNamedArguments ? new Identifier('code') : null);
$new->args[$exceptionArgumentPosition] = $arg1;
} else {
$new->args[$exceptionArgumentPosition] = new Arg($catchedThrowableVariable, \false, \false, [], $shouldUseNamedArguments ? new Identifier('previous') : null);
$new->args[$exceptionArgumentPosition] = new Arg($caughtThrowableVariable, \false, \false, [], $shouldUseNamedArguments ? new Identifier('previous') : null);
}
// null the node, to fix broken format preserving printers, see https://github.com/rectorphp/rector/issues/5576
$new->setAttribute(AttributeKey::ORIGINAL_NODE, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private function createNewPropertyFromPropertyTagValueNodes(array $propertyPhpDo
}
// is property already defined?
if ($class->getProperty($propertyName) instanceof Property) {
// improve exising one type if needed
// improve existing one type if needed
$existingProperty = $class->getProperty($propertyName);
if ($existingProperty->type instanceof Node) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SomeClass
public function run(int $firstValue, int $secondValue)
{
$isSame = $firstValue == $secondValue;
$isDiffernt = $firstValue != $secondValue;
$isDifferent = $firstValue != $secondValue;
}
}
CODE_SAMPLE
Expand All @@ -36,7 +36,7 @@ class SomeClass
public function run(int $firstValue, int $secondValue)
{
$isSame = $firstValue === $secondValue;
$isDiffernt = $firstValue !== $secondValue;
$isDifferent = $firstValue !== $secondValue;
}
}
CODE_SAMPLE
Expand Down
8 changes: 4 additions & 4 deletions rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ private function matchNodes($binaryOp, Expr $expr) : ?TwoNodeMatch
}
private function isIfBodyABoolReturnNode(If_ $if) : bool
{
$ifStatment = $if->stmts[0];
if (!$ifStatment instanceof Return_) {
$ifStatement = $if->stmts[0];
if (!$ifStatement instanceof Return_) {
return \false;
}
if (!$ifStatment->expr instanceof Expr) {
if (!$ifStatement->expr instanceof Expr) {
return \false;
}
return $this->valueResolver->isTrueOrFalse($ifStatment->expr);
return $this->valueResolver->isTrueOrFalse($ifStatement->expr);
}
/**
* @param \PhpParser\Node\Expr\BinaryOp\Identical|\PhpParser\Node\Expr\BinaryOp\Equal $binaryOp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class AndAssignsToSeparateLinesRector extends AbstractRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Split 2 assigns ands to separate line', [new CodeSample(<<<'CODE_SAMPLE'
return new RuleDefinition('Split 2 assigns and to separate line', [new CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* @see \Rector\Tests\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector\SymplifyQuoteEscapeRectorTest
*/
final class SymplifyQuoteEscapeRector extends AbstractRector
final class SimplifyQuoteEscapeRector extends AbstractRector
{
/**
* @var string
Expand Down
6 changes: 3 additions & 3 deletions rules/DeadCode/NodeAnalyzer/CallCollectionAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function isExists(array $calls, string $classMethodName, string $classNam
foreach ($calls as $call) {
$callerRoot = $call instanceof StaticCall ? $call->class : $call->var;
$callerType = $this->nodeTypeResolver->getType($callerRoot);
$callerTypeClasName = ClassNameFromObjectTypeResolver::resolve($callerType);
if ($callerTypeClasName === null) {
$callerTypeClassName = ClassNameFromObjectTypeResolver::resolve($callerType);
if ($callerTypeClassName === null) {
// handle fluent by $this->bar()->baz()->qux()
// that methods don't have return type
if ($callerType instanceof MixedType && !$callerType->isExplicitMixed()) {
Expand All @@ -65,7 +65,7 @@ public function isExists(array $calls, string $classMethodName, string $classNam
if ($this->isSelfStatic($call) && $this->shouldSkip($call, $classMethodName)) {
return \true;
}
if ($callerTypeClasName !== $className) {
if ($callerTypeClassName !== $className) {
continue;
}
if ($this->shouldSkip($call, $classMethodName)) {
Expand Down
4 changes: 2 additions & 2 deletions rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private function isDeadNotEqual(ReturnTagValueNode $returnTagValueNode, Node $no
if ($returnTagValueNode->type instanceof IdentifierTypeNode && (string) $returnTagValueNode->type === 'void') {
return \true;
}
if (!$this->hasUsefullPhpdocType($returnTagValueNode, $node)) {
if (!$this->hasUsefulPhpdocType($returnTagValueNode, $node)) {
return \true;
}
$nodeType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($node);
Expand All @@ -140,7 +140,7 @@ private function hasTrueFalsePseudoType(BracketsAwareUnionTypeNode $bracketsAwar
* exact different between @return and node return type
* @param mixed $returnType
*/
private function hasUsefullPhpdocType(ReturnTagValueNode $returnTagValueNode, $returnType) : bool
private function hasUsefulPhpdocType(ReturnTagValueNode $returnTagValueNode, $returnType) : bool
{
if ($returnTagValueNode->type instanceof IdentifierTypeNode && $returnTagValueNode->type->name === 'mixed') {
return \false;
Expand Down
2 changes: 1 addition & 1 deletion rules/DeadCode/Rector/Assign/RemoveDoubleAssignRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function refactor(Node $node) : ?Node
if (!$stmt->expr->var instanceof Variable && !$stmt->expr->var instanceof PropertyFetch && !$stmt->expr->var instanceof StaticPropertyFetch) {
continue;
}
// remove current Stmt if will be overriden in next stmt
// remove current Stmt if will be overridden in next stmt
unset($node->stmts[$key]);
$hasChanged = \true;
}
Expand Down
4 changes: 2 additions & 2 deletions rules/DeadCode/Rector/Concat/RemoveConcatAutocastRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class RemoveConcatAutocastRector extends AbstractRector
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Remove (string) casting when it comes to concat, that does this by default', [new CodeSample(<<<'CODE_SAMPLE'
class SomeConcatingClass
class SomeConcatenatingClass
{
public function run($value)
{
Expand All @@ -27,7 +27,7 @@ public function run($value)
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeConcatingClass
class SomeConcatenatingClass
{
public function run($value)
{
Expand Down
4 changes: 2 additions & 2 deletions rules/DeadCode/Rector/For_/RemoveDeadIfForeachForRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getRuleDefinition() : RuleDefinition
return new RuleDefinition('Remove if, foreach and for that does not do anything', [new CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value, $differrentValue)
public function run($value, $differentValue)
{
if ($value) {
}
Expand All @@ -63,7 +63,7 @@ public function run($value, $differrentValue)
, <<<'CODE_SAMPLE'
class SomeClass
{
public function run($value, $differrentValue)
public function run($value, $differentValue)
{
return $differentValue;
}
Expand Down
10 changes: 5 additions & 5 deletions rules/Naming/Guard/BreakingVariableRenameGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class BreakingVariableRenameGuard
/**
* @readonly
*/
private OverridenExistingNamesResolver $overridenExistingNamesResolver;
private OverriddenExistingNamesResolver $overriddenExistingNamesResolver;
/**
* @readonly
*/
Expand All @@ -57,12 +57,12 @@ final class BreakingVariableRenameGuard
* @see https://regex101.com/r/1pKLgf/1
*/
public const AT_NAMING_REGEX = '#[\\w+]At$#';
public function __construct(BetterNodeFinder $betterNodeFinder, ConflictingNameResolver $conflictingNameResolver, NodeTypeResolver $nodeTypeResolver, OverridenExistingNamesResolver $overridenExistingNamesResolver, TypeUnwrapper $typeUnwrapper, NodeNameResolver $nodeNameResolver)
public function __construct(BetterNodeFinder $betterNodeFinder, ConflictingNameResolver $conflictingNameResolver, NodeTypeResolver $nodeTypeResolver, OverriddenExistingNamesResolver $overriddenExistingNamesResolver, TypeUnwrapper $typeUnwrapper, NodeNameResolver $nodeNameResolver)
{
$this->betterNodeFinder = $betterNodeFinder;
$this->conflictingNameResolver = $conflictingNameResolver;
$this->nodeTypeResolver = $nodeTypeResolver;
$this->overridenExistingNamesResolver = $overridenExistingNamesResolver;
$this->overriddenExistingNamesResolver = $overriddenExistingNamesResolver;
$this->typeUnwrapper = $typeUnwrapper;
$this->nodeNameResolver = $nodeNameResolver;
}
Expand All @@ -79,7 +79,7 @@ public function shouldSkipVariable(string $currentName, string $expectedName, $f
if ($this->conflictingNameResolver->hasNameIsInFunctionLike($expectedName, $functionLike)) {
return \true;
}
if (!$functionLike instanceof ArrowFunction && $this->overridenExistingNamesResolver->hasNameInClassMethodForNew($currentName, $functionLike)) {
if (!$functionLike instanceof ArrowFunction && $this->overriddenExistingNamesResolver->hasNameInClassMethodForNew($currentName, $functionLike)) {
return \true;
}
if ($this->isVariableAlreadyDefined($variable, $currentName)) {
Expand Down Expand Up @@ -107,7 +107,7 @@ public function shouldSkipParam(string $currentName, string $expectedName, $clas
if ($this->conflictingNameResolver->hasNameIsInFunctionLike($expectedName, $classMethod)) {
return \true;
}
if ($this->overridenExistingNamesResolver->hasNameInFunctionLikeForParam($expectedName, $classMethod)) {
if ($this->overriddenExistingNamesResolver->hasNameInFunctionLikeForParam($expectedName, $classMethod)) {
return \true;
}
if ($param->var instanceof Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ private function resolve(ClassLike $classLike) : array
}
$expectedNames[] = $expectedName;
}
return $this->arrayFilter->filterWithAtLeastTwoOccurences($expectedNames);
return $this->arrayFilter->filterWithAtLeastTwoOccurrences($expectedNames);
}
}
4 changes: 2 additions & 2 deletions rules/Naming/Naming/ConflictingNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function resolveConflictingVariableNamesForParam($classMethod) : array
}
$expectedNames[] = $expectedName;
}
return $this->arrayFilter->filterWithAtLeastTwoOccurences($expectedNames);
return $this->arrayFilter->filterWithAtLeastTwoOccurrences($expectedNames);
}
/**
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $functionLike
Expand All @@ -85,7 +85,7 @@ private function resolveConflictingVariableNamesForNew($functionLike) : array
$newAssignNames = $this->resolveForNewAssigns($functionLike);
$nonNewAssignNames = $this->resolveForNonNewAssigns($functionLike);
$protectedNames = \array_merge($paramNames, $newAssignNames, $nonNewAssignNames);
$protectedNames = $this->arrayFilter->filterWithAtLeastTwoOccurences($protectedNames);
$protectedNames = $this->arrayFilter->filterWithAtLeastTwoOccurrences($protectedNames);
$this->conflictingVariableNamesByClassMethod[$classMethodId] = $protectedNames;
return $protectedNames;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Rector\Naming\PhpArray\ArrayFilter;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpParser\Node\BetterNodeFinder;
final class OverridenExistingNamesResolver
final class OverriddenExistingNamesResolver
{
/**
* @readonly
Expand All @@ -29,7 +29,7 @@ final class OverridenExistingNamesResolver
/**
* @var array<int, array<int, string>>
*/
private array $overridenExistingVariableNamesByClassMethod = [];
private array $overriddenExistingVariableNamesByClassMethod = [];
public function __construct(ArrayFilter $arrayFilter, BetterNodeFinder $betterNodeFinder, NodeNameResolver $nodeNameResolver)
{
$this->arrayFilter = $arrayFilter;
Expand All @@ -41,8 +41,8 @@ public function __construct(ArrayFilter $arrayFilter, BetterNodeFinder $betterNo
*/
public function hasNameInClassMethodForNew(string $variableName, $functionLike) : bool
{
$overridenVariableNames = $this->resolveOveriddenNamesForNew($functionLike);
return \in_array($variableName, $overridenVariableNames, \true);
$overriddenVariableNames = $this->resolveOverriddenNamesForNew($functionLike);
return \in_array($variableName, $overriddenVariableNames, \true);
}
/**
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $classMethod
Expand All @@ -68,11 +68,11 @@ public function hasNameInFunctionLikeForParam(string $expectedName, $classMethod
* @return string[]
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/
private function resolveOveriddenNamesForNew($functionLike) : array
private function resolveOverriddenNamesForNew($functionLike) : array
{
$classMethodId = \spl_object_id($functionLike);
if (isset($this->overridenExistingVariableNamesByClassMethod[$classMethodId])) {
return $this->overridenExistingVariableNamesByClassMethod[$classMethodId];
if (isset($this->overriddenExistingVariableNamesByClassMethod[$classMethodId])) {
return $this->overriddenExistingVariableNamesByClassMethod[$classMethodId];
}
$currentlyUsedNames = [];
/** @var Assign[] $assigns */
Expand All @@ -86,8 +86,8 @@ private function resolveOveriddenNamesForNew($functionLike) : array
}
$currentlyUsedNames[] = $currentVariableName;
}
$currentlyUsedNames = $this->arrayFilter->filterWithAtLeastTwoOccurences($currentlyUsedNames);
$this->overridenExistingVariableNamesByClassMethod[$classMethodId] = $currentlyUsedNames;
$currentlyUsedNames = $this->arrayFilter->filterWithAtLeastTwoOccurrences($currentlyUsedNames);
$this->overriddenExistingVariableNamesByClassMethod[$classMethodId] = $currentlyUsedNames;
return $currentlyUsedNames;
}
}
2 changes: 1 addition & 1 deletion rules/Naming/PhpArray/ArrayFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class ArrayFilter
* @param mixed[] $values
* @return string[]
*/
public function filterWithAtLeastTwoOccurences(array $values) : array
public function filterWithAtLeastTwoOccurrences(array $values) : array
{
/** @var array<string, int> $valueToCount */
$valueToCount = \array_count_values($values);
Expand Down
2 changes: 1 addition & 1 deletion rules/Php70/EregToPcreTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ final class EregToPcreTransformer
*/
private array $cache = [];
/**
* Change this via services configuratoin in rector.php if you need it
* Change this via services configuration in rector.php if you need it
* Single type is chosen to prevent every regular with different delimiter.
*/
public function __construct(string $pcreDelimiter = '#')
Expand Down
2 changes: 1 addition & 1 deletion rules/Php70/Rector/If_/IfToSpaceshipRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function refactor(Node $node) : ?Node
if (!$stmt->expr instanceof Ternary) {
continue;
}
// preceeded by if
// preceded by if
$prevStmt = $node->stmts[$key - 1] ?? null;
if (!$prevStmt instanceof If_) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion rules/Php80/Rector/Class_/StringableForToStringRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function refactor(Node $node) : ?Node
return null;
}
$this->hasChanged = \false;
// warning, classes that implements __toString() will return Stringable interface even if they don't implemen it
// warning, classes that implements __toString() will return Stringable interface even if they don't implement it
// reflection cannot be used for real detection
$classLikeAncestorNames = $this->familyRelationsAnalyzer->getClassLikeAncestorNames($node);
$isAncestorHasStringable = \in_array(self::STRINGABLE, $classLikeAncestorNames, \true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use Rector\NodeNameResolver\NodeNameResolver;
final class CoalesePropertyAssignMatcher
final class CoalescePropertyAssignMatcher
{
/**
* @readonly
Expand Down
Loading