Skip to content

Commit

Permalink
[Php56] Skip already initialized on next Stmt on AddDefaultValueForUn…
Browse files Browse the repository at this point in the history
…definedVariableRector (#2721)

* [Php56] Skip already initialized on next Stmt on AddDefaultValueForUndefinedVariableRector

* Fixed 🎉

* [ci-review] Rector Rectify

* clean up

* phpstan

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Jul 29, 2022
1 parent ec291c4 commit 7ca5096
Show file tree
Hide file tree
Showing 104 changed files with 177 additions and 130 deletions.
Expand Up @@ -227,7 +227,7 @@ private function isClosedContent(string $composedContent): bool
$composedTokenIterator->isCurrentTokenType(
Lexer::TOKEN_CLOSE_CURLY_BRACKET,
Lexer::TOKEN_CLOSE_PARENTHESES
// sometimes it gets mixed int ")
// sometimes it gets mixed int ")
) || \str_contains($composedTokenIterator->currentTokenValue(), ')')) {
++$closeBracketCount;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/NodeTypeResolver/TypeAnalyzer/MethodTypeAnalyzer.php
Expand Up @@ -37,8 +37,8 @@ public function isCallTo(MethodCall $methodCall, string $expectedClass, string $
private function isMethodName(MethodCall $methodCall, string $expectedName): bool
{
if (
$methodCall->name instanceof Identifier
&& $this->areMethodNamesEqual($methodCall->name->toString(), $expectedName)
$methodCall->name instanceof Identifier
&& $this->areMethodNamesEqual($methodCall->name->toString(), $expectedName)
) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/PostRector/Rector/ClassRenamingPostRector.php
Expand Up @@ -43,7 +43,7 @@ function (OriginalClass $someClass)
{
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
function (RenamedClass $someClass)
{
Expand Down
2 changes: 1 addition & 1 deletion packages/PostRector/Rector/NameImportingPostRector.php
Expand Up @@ -79,7 +79,7 @@ public function run(App\AnotherClass $anotherClass)
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
use App\AnotherClass;
Expand Down
2 changes: 1 addition & 1 deletion packages/PostRector/Rector/NodeRemovingPostRector.php
Expand Up @@ -103,7 +103,7 @@ public function run($value)
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
2 changes: 1 addition & 1 deletion packages/PostRector/Rector/PropertyAddingPostRector.php
Expand Up @@ -65,7 +65,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
2 changes: 1 addition & 1 deletion packages/PostRector/Rector/UseAddingPostRector.php
Expand Up @@ -105,7 +105,7 @@ public function run(AnotherClass $anotherClass)
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
use App\AnotherClass;
Expand Down
@@ -0,0 +1,23 @@
<?php

namespace Rector\Tests\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector\Fixture;

class SkipAlreadyInitializedNext
{
public function run()
{
$a = null;
$b = null;

if (rand(0, 1)) {
$a = 5;
$b = 2;
} else if (rand(0,1)) {
unset($a);
unset($b);
}

echo $a;
echo $b;
}
}
Expand Up @@ -44,7 +44,7 @@ public function getRuleDefinition(): RuleDefinition
<<<'CODE_SAMPLE'
version_compare(PHP_VERSION, '5.6', 'ge');
CODE_SAMPLE
,
,
[new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'gte', 'ge',)]
),
]);
Expand Down
Expand Up @@ -37,7 +37,7 @@ public function run(Caller $caller)
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
final class SomeClass
{
Expand All @@ -47,7 +47,7 @@ public function run(Caller $caller)
}
}
CODE_SAMPLE
,
,
[new RemoveMethodCallParam('Caller', 'process', 1)]
),
]);
Expand Down
Expand Up @@ -36,7 +36,7 @@ public function run(): void
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
final class SomeClass
{
Expand Down
Expand Up @@ -45,7 +45,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -44,7 +44,7 @@ public function run($items)
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -44,7 +44,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -33,7 +33,7 @@ public function getRuleDefinition(): RuleDefinition
<<<'CODE_SAMPLE'
'#' . preg_quote('name') . '#';
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
'#' . preg_quote('name', '#') . '#';
CODE_SAMPLE
Expand Down
Expand Up @@ -33,7 +33,7 @@ function run($packageName, $values)
return in_array($packageName, $keys, true);
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
function run($packageName, $values)
{
Expand Down
Expand Up @@ -40,7 +40,7 @@ public function go()
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -31,7 +31,7 @@ public function getRuleDefinition(): RuleDefinition
$items = [];
array_push($items, $item);
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
$items = [];
$items[] = $item;
Expand Down
Expand Up @@ -34,7 +34,7 @@ public function run($value)
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -50,7 +50,7 @@ public function run(): void
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -36,7 +36,7 @@ public function run($values, $keyToMatch)
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -117,7 +117,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
[
self::DELIMITER => '#',
]
Expand Down
Expand Up @@ -39,7 +39,7 @@ public function getRuleDefinition(): RuleDefinition
count($array) > 0;
! count($array);
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
$array === [];
$array !== [];
Expand Down
Expand Up @@ -39,7 +39,7 @@ class SomeClass
private $isDisabled;
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -62,7 +62,7 @@ final class SomeClass
private ?array $dateTimes;
}
CODE_SAMPLE
,
,
['var', 'phpstan-var'],
),
]
Expand Down
Expand Up @@ -30,7 +30,7 @@ class SomeClass
use SomeTrait, AnotherTrait;
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
use A;
use B;
Expand Down
4 changes: 2 additions & 2 deletions rules/Composer/Rector/RemovePackageComposerRector.php
Expand Up @@ -38,12 +38,12 @@ public function getRuleDefinition(): RuleDefinition
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
{
}
CODE_SAMPLE
,
,
['symfony/console']
),
]);
Expand Down
Expand Up @@ -58,7 +58,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -40,7 +40,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
4 changes: 2 additions & 2 deletions rules/DeadCode/Rector/ClassLike/RemoveAnnotationRector.php
Expand Up @@ -44,13 +44,13 @@ final class SomeClass
{
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
final class SomeClass
{
}
CODE_SAMPLE
,
,
['method'],
),
]);
Expand Down
Expand Up @@ -76,7 +76,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand All @@ -86,7 +86,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
[PhpVersion::PHP_80]
),
],
Expand Down
Expand Up @@ -63,7 +63,7 @@ public function run($value)
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -51,7 +51,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -41,7 +41,7 @@ public function getRuleDefinition(): RuleDefinition
return 'is PHP 7.2+';
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
// current PHP: 7.2
return 'is PHP 7.2+';
Expand Down
Expand Up @@ -63,7 +63,7 @@ class SomeClass
{
}
CODE_SAMPLE
,
,
[
self::REMOVE_ASSIGN_SIDE_EFFECT => true,
]
Expand Down
Expand Up @@ -35,7 +35,7 @@ private function getBool(): bool
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -37,7 +37,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -53,7 +53,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
Expand Up @@ -50,7 +50,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down

0 comments on commit 7ca5096

Please sign in to comment.