-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent exceptions on UnionTypes (#2)
Co-authored-by: Pascal Heidmann <pascal.heidmann@check24.de> See: #2
- Loading branch information
1 parent
2834446
commit 43d7300
Showing
4 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
...s/Rule/CurrencyAvailableWithinToCurrenciesContainsRector/Fixture/skip_union_types.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,28 @@ | ||
<?php | ||
|
||
namespace Rector\Money\Tests\Rule\CurrencyAvailableWithinToCurrenciesContainsRector\Fixture; | ||
|
||
use Money\Currencies\CurrencyList; | ||
use Money\Currency; | ||
use function mt_rand; | ||
|
||
/** | ||
* @return Currency|array|false | ||
*/ | ||
function willReturnCurrencyOrSomethingDifferent() { | ||
$random = mt_rand(0, 10); | ||
if ($random % 3 === 0) { | ||
return new Currency('EUR'); | ||
} | ||
if ($random === 5) { | ||
return ['some' => 'other', 'data']; | ||
} | ||
return false; | ||
} | ||
|
||
$collection = new CurrencyList([new Currency('PLN')]); | ||
willReturnCurrencyOrSomethingDifferent() | ||
->isAvailableWithin($collection); | ||
|
||
?> | ||
|
44 changes: 44 additions & 0 deletions
44
tests/Rule/MultiplyAndDivideByStringRector/Fixture/skip_union_types.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,44 @@ | ||
<?php | ||
|
||
namespace Rector\Money\Tests\Rule\MultiplyAndDivideByStringRector\Fixture; | ||
|
||
use Money\Currency; | ||
use Money\Money; | ||
use function mt_rand; | ||
|
||
class UnionReturning | ||
{ | ||
/** | ||
* @return Money|array|false | ||
*/ | ||
public static function foo() | ||
{ | ||
$random = mt_rand(0, 10); | ||
if ($random % 3 === 0) { | ||
return new Money($random, new Currency('EUR')); | ||
} | ||
if ($random === 5) { | ||
return ['some' => 'other', 'data']; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @return Money|array|false | ||
*/ | ||
public function bar() | ||
{ | ||
return self::foo(); | ||
} | ||
} | ||
|
||
$unionReturning = new UnionReturning(); | ||
$unionReturning->bar()->divide(1); | ||
$unionReturning->bar()->multiply(2); | ||
$unionReturning->bar()->divide(1.1); | ||
$unionReturning->bar()->multiply(2.5); | ||
|
||
UnionReturning::foo()->divide(3); | ||
UnionReturning::foo()->multiply(4); | ||
UnionReturning::foo()->divide(3.5); | ||
UnionReturning::foo()->multiply(4.6); |