Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Nop;
use PhpParser\Node\Stmt\While_;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
Expand Down Expand Up @@ -82,6 +83,11 @@ public function refactor(Node $node): ?Node
return null;
}

if ($previousNode instanceof While_) {
$node->setAttribute(AttributeKey::IS_UNREACHABLE, false);
return null;
}

if ($this->isAfterMarkTestSkippedMethodCall($node)) {
$node->setAttribute(AttributeKey::IS_UNREACHABLE, false);
return null;
Expand Down Expand Up @@ -144,6 +150,7 @@ private function isBreakingScopeNode(Node $node): bool
if ($node instanceof Namespace_) {
return true;
}

return $node instanceof Else_;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Rector\PHPUnit\Tests\Rector\MethodCall\WithConsecutiveArgToArrayRector\Fixture;

use PHPUnit\Framework\TestCase;
use Rector\PHPUnit\Tests\Rector\MethodCall\WithConsecutiveArgToArrayRector\ClassWithMethodOfTwoArguments;
use Rector\PHPUnit\Tests\Rector\MethodCall\WithConsecutiveArgToArrayRector\Source\ClassWithMethodOfTwoArguments;

class SkipAlreadyArrayTestCase extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

declare(strict_types=1);

namespace Rector\PHPUnit\Tests\Rector\MethodCall\WithConsecutiveArgToArrayRector;
namespace Rector\PHPUnit\Tests\Rector\MethodCall\WithConsecutiveArgToArrayRector\Source;

final class ClassWithMethodOfTwoArguments
{
public function go(int $one, string $two): void
{
$three = $one + $two;
}
}
1 change: 1 addition & 0 deletions rector-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
sets:
- "code-quality"
- "dead-code"

auto_import_names: true

Expand Down
9 changes: 9 additions & 0 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Console;

use Composer\XdebugHandler\XdebugHandler;
use Jean85\PrettyVersions;
use Rector\Configuration\Configuration;
use Rector\Console\Output\JsonOutputFormatter;
Expand Down Expand Up @@ -55,6 +56,14 @@ public function setDispatcher(EventDispatcherInterface $eventDispatcher): void

public function doRun(InputInterface $input, OutputInterface $output): int
{
// @fixes https://github.com/rectorphp/rector/issues/2205
$isXdebugAllowed = $input->hasParameterOption('--xdebug');
if (!$isXdebugAllowed) {
$xdebug = new XdebugHandler('rector', '--ansi');
$xdebug->check();
unset($xdebug);
}

$this->configuration->setConfigFilePathFromInput($input);

$shouldFollowByNewline = false;
Expand Down
8 changes: 0 additions & 8 deletions src/Console/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\Console\Command;

use Composer\XdebugHandler\XdebugHandler;
use Nette\Utils\Strings;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Descriptor\TextDescriptor;
Expand Down Expand Up @@ -61,12 +60,5 @@ protected function initialize(InputInterface $input, OutputInterface $output): v

$this->getApplication()->setCatchExceptions(false);
}

// @fixes https://github.com/rectorphp/rector/issues/2205
if ($input->getOption('xdebug')) {
$xdebug = new XdebugHandler('rector', '--ansi');
$xdebug->check();
unset($xdebug);
}
}
}
5 changes: 5 additions & 0 deletions src/PhpParser/Node/Manipulator/ClassManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt;
Expand Down Expand Up @@ -487,6 +488,10 @@ private function getClassMethodNames(Class_ $classNode): array
private function isNonAssignPropertyFetch(Node $node): bool
{
if ($node instanceof PropertyFetch) {
if (! $node->var instanceof Variable) {
return false;
}

if (! $this->nameResolver->isName($node->var, 'this')) {
return false;
}
Expand Down
11 changes: 10 additions & 1 deletion src/PhpParser/Node/Resolver/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use PhpParser\Node\Stmt\Use_;
use Rector\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\PackageBuilder\FileSystem\SmartFileInfo;

final class NameResolver
{
Expand All @@ -44,8 +45,16 @@ public function isNames(Node $node, array $names): bool
public function isName(Node $node, string $name): bool
{
if ($node instanceof MethodCall) {
$debugBacktrace = debug_backtrace();

$previousCaller = $debugBacktrace[0];
$fileInfo = new SmartFileInfo($previousCaller['file']);
$location = $fileInfo->getRelativeFilePathFromDirectory(getcwd()) . ':' . $previousCaller['line'];

throw new ShouldNotHappenException(sprintf(
'Cannot get name on "%s" node. Use $node->name instead', MethodCall::class
'Cannot get name on "%s" node. Use $node->name instead. Called in: %s',
MethodCall::class,
$location
));
}

Expand Down