-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve native return-type from native union-type in short ternary (#…
…4606) * Resolve native type from method call in short ternary * Update ReturnTypeFromStrictTernaryRector.php * fix class-name conflict * Update return_from_ternary_phpdoc.php.inc * fix * Update skip_union_void.inc * Update skip_union_void.inc * more gracefull error handling * Update rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php --------- Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
- Loading branch information
1 parent
729f03b
commit c01925a
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...ation/Rector/Class_/ReturnTypeFromStrictTernaryRector/Fixture/return_from_ternary.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,39 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture; | ||
|
||
class Appointment | ||
{ | ||
private function find_one(): self|false { | ||
return false; | ||
} | ||
|
||
public function getRent() | ||
{ | ||
$rent = $this->find_one(); | ||
|
||
return $rent ?: null; | ||
} | ||
|
||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture; | ||
|
||
class Appointment | ||
{ | ||
private function find_one(): self|false { | ||
return false; | ||
} | ||
|
||
public function getRent(): ?\Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture\Appointment | ||
{ | ||
$rent = $this->find_one(); | ||
|
||
return $rent ?: null; | ||
} | ||
|
||
} | ||
?> |
20 changes: 20 additions & 0 deletions
20
...peDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector/Fixture/skip_union_void.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,20 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture; | ||
|
||
class SkipUnionVoid | ||
{ | ||
private function find_one(): self|false { | ||
return false; | ||
} | ||
|
||
public function getRent() | ||
{ | ||
if (random_int(0 ,1 )) { | ||
$rent = $this->find_one(); | ||
|
||
return $rent ?: null; | ||
} | ||
} | ||
|
||
} |
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