Add not refactorable testCases; clearify recursion

This commit is contained in:
Jonas Elfering 2019-10-04 14:36:48 +02:00
parent 0196d1efee
commit 3f509a2dd4
4 changed files with 143 additions and 1 deletions

View File

@ -84,7 +84,11 @@ PHP
return null;
}
$if = $this->refactor($if) ?? $if;
$refactored = $this->refactor($if);
if ($refactored) {
$if = $refactored;
}
$node->elseifs[] = new ElseIf_(
$if->cond,

View File

@ -0,0 +1,71 @@
<?php
namespace Rector\Php\Tests\Rector\If_\ShortenElseIfRector\Fixture;
class MultipleStmtsClass
{
/**
* @var bool
*/
private $cond1;
/**
* @var bool
*/
private $cond2;
public function run()
{
if ($this->cond1) {
$this->doSomething();
} else {
if ($this->cond2) {
$this->doSomething();
}
$this->doSomething();
}
}
public function doSomething()
{
}
}
?>
-----
<?php
namespace Rector\Php\Tests\Rector\If_\ShortenElseIfRector\Fixture;
class MultipleStmtsClass
{
/**
* @var bool
*/
private $cond1;
/**
* @var bool
*/
private $cond2;
public function run()
{
if ($this->cond1) {
$this->doSomething();
} else {
if ($this->cond2) {
$this->doSomething();
}
$this->doSomething();
}
}
public function doSomething()
{
}
}
?>

View File

@ -0,0 +1,65 @@
<?php
namespace Rector\Php\Tests\Rector\If_\ShortenElseIfRector\Fixture;
class NoElseIfClass
{
/**
* @var bool
*/
private $cond1;
/**
* @var bool
*/
private $cond2;
public function run()
{
if ($this->cond1) {
$this->doSomething();
} else {
$this->doSomething();
}
}
public function doSomething()
{
}
}
?>
-----
<?php
namespace Rector\Php\Tests\Rector\If_\ShortenElseIfRector\Fixture;
class NoElseIfClass
{
/**
* @var bool
*/
private $cond1;
/**
* @var bool
*/
private $cond2;
public function run()
{
if ($this->cond1) {
$this->doSomething();
} else {
$this->doSomething();
}
}
public function doSomething()
{
}
}
?>

View File

@ -22,6 +22,8 @@ final class ShortenElseIfRectorTest extends AbstractRectorTestCase
yield [__DIR__ . '/Fixture/nested-else.php.inc'];
yield [__DIR__ . '/Fixture/nested-elseif.php.inc'];
yield [__DIR__ . '/Fixture/recursive.php.inc'];
yield [__DIR__ . '/Fixture/no-else-if.php.inc'];
yield [__DIR__ . '/Fixture/multiple-stmts.php.inc'];
}
protected function getRectorClass(): string