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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Tests\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector\Fixture;

class Fixture
class SingleIf
{
public function run($var)
{
Expand All @@ -11,10 +11,6 @@ class Fixture
$var = 1 ;
}

if (rand(0,2)) {
$var = 2 ;
}

return $var;
}
}
Expand All @@ -25,18 +21,14 @@ class Fixture

namespace Rector\Tests\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector\Fixture;

class Fixture
class SingleIf
{
public function run($var)
{
if (rand(0,1)) {
return 1;
}

if (rand(0,2)) {
return 2;
}

return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Rector\Tests\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector\Fixture;

class SkipFixture
{
public function run($var)
{
$var = null;
if (rand(0,1)) {
$var = 1 ;
}

if (rand(0,2)) {
$var = 2 ;
}

return $var;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Rector\Tests\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector\Fixture;

class SkipInsideIf
{
public function run($var)
{
if (rand(0, 1)) {
$var = null;
if (rand(0,1)) {
$var = 1 ;
}

if (rand(0,2)) {
$var = 2 ;
}

return $var;
}
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Rector\Tests\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector\Fixture;

class SkipPreviousIndirectIf
{
public function run($var)
{
$var = null;
echo 'a statement';
if (rand(0,1)) {
$var = 1 ;
}

if (rand(0,2)) {
$var = 2 ;
}

return $var;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ public function run()
$var = 1;
}

if (rand(0, 1)) {
$var = 2;
}

return $var;
}
}
Expand All @@ -70,10 +66,6 @@ public function run()
return 1;
}

if (rand(0, 1)) {
return 2;
}

return null;
}
}
Expand Down Expand Up @@ -158,7 +150,8 @@ public function refactor(Node $node): ?Node

$matchingBareSingleAssignIfs = $this->getMatchingBareSingleAssignIfs($ifs, $node);

if ($matchingBareSingleAssignIfs === []) {
// several ifs: the last true one wins, early returns would make the first one win
if (count($matchingBareSingleAssignIfs) !== 1) {
return null;
}

Expand Down
Loading