Skip to content

Commit

Permalink
[prevent-non-class-exceptions] add new test cases for skipping union …
Browse files Browse the repository at this point in the history
…types
  • Loading branch information
pascalheidmann-check24 committed Jun 24, 2022
1 parent bf4666b commit 7037383
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
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);

?>

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

namespace Rector\Money\Tests\Rule\MultiplyAndDivideByStringRector\Fixture;

use Money\Currency;
use Money\Money;
use function mt_rand;

function returnInt(): int
{
return 1;
}

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::foo()->divide(3);
UnionReturning::foo()->multiply(4);

0 comments on commit 7037383

Please sign in to comment.