-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ReturnTypeFromStrictTernaryRector: Support complex ternaries (#4515)
- Loading branch information
Showing
7 changed files
with
145 additions
and
111 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
.../TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector/Fixture/function.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture; | ||
|
||
function getValue($number) | ||
{ | ||
return $number ? 'a' : 'b'; | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture; | ||
|
||
function getValue($number): string | ||
{ | ||
return $number ? 'a' : 'b'; | ||
} | ||
|
||
?> |
22 changes: 22 additions & 0 deletions
22
...eDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector/Fixture/skip_phpdocs.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture; | ||
|
||
final class SkipPhpdocs | ||
{ | ||
public function getValue() | ||
{ | ||
$x = false; | ||
if (rand(0,1)) { | ||
$x = $this->get(); | ||
} | ||
return $x ?: null; | ||
} | ||
|
||
/** | ||
* @return SkipPhpdocs | ||
*/ | ||
public function get() {} | ||
} | ||
|
||
?> |
24 changes: 24 additions & 0 deletions
24
...aration/Rector/Class_/ReturnTypeFromStrictTernaryRector/Fixture/skip_wrong_return.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture; | ||
|
||
final class SkipWrongReturn | ||
{ | ||
public function getValue() | ||
{ | ||
$x = false; | ||
if (rand(0,1)) { | ||
$x = $this->get(); | ||
} | ||
|
||
if (rand(0,1)) { | ||
return $x ?: null; | ||
} | ||
|
||
// missing return | ||
} | ||
|
||
public function get(): SkipWrongReturn {} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...on/Rector/Class_/ReturnTypeFromStrictTernaryRector/Fixture/ternary_short_var_call.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture; | ||
|
||
final class CallInShortTernaryVar | ||
{ | ||
public function getValue() | ||
{ | ||
return $this->get() ?: null; | ||
} | ||
|
||
public function get(): CallInShortTernaryVar|false {} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture; | ||
|
||
final class CallInShortTernaryVar | ||
{ | ||
public function getValue(): ?\Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture\CallInShortTernaryVar | ||
{ | ||
return $this->get() ?: null; | ||
} | ||
|
||
public function get(): CallInShortTernaryVar|false {} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.