Skip to content

Commit

Permalink
Fix/early return inline constructor default 7319 (#2716)
Browse files Browse the repository at this point in the history
* fix: inline constructor default when early return

* test: inline constructor default when early return
  • Loading branch information
kpn13 committed Jul 27, 2022
1 parent fe0551e commit 4ed677d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector\Fixture;

final class DonotChangeHasBeforeIf
{
private $name;
private $age;
private $gender;

public function __construct(bool $initName = true)
{
$this->age = 20;

if (!$initName) {
$this->gender = 'M';

return;
}

$this->name = 'John';
}
}
?>
-----
<?php

namespace Rector\Tests\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector\Fixture;

final class DonotChangeHasBeforeIf
{
private $name;
private $age = 20;
private $gender;

public function __construct(bool $initName = true)
{
if (!$initName) {
$this->gender = 'M';

return;
}

$this->name = 'John';
}
}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function resolve(ClassMethod $classMethod): array

foreach ($stmts as $stmt) {
if (! $stmt instanceof Expression) {
continue;
break;
}

$nestedStmt = $stmt->expr;
Expand Down

0 comments on commit 4ed677d

Please sign in to comment.