-
-
Notifications
You must be signed in to change notification settings - Fork 737
Closed
rectorphp/rector-src
#2935Labels
Description
Bug Report
| Subject | Details |
|---|---|
| Rector version | last dev-main |
| Installed as | composer dependency |
Minimal PHP Code Causing Issue
See https://getrector.org/demo/e30d69ac-ec54-4bcd-b58b-78e14c498bfd
<?php
class A
{
/**
* @return array|null
* @throws Exception
*/
public function getTierPrices()
{
return random_int(0, 1) ? [] : null;
}
}
class B
{
public function getPrice(A $product): float
{
$tierPrices = $product->getTierPrices();
if (!empty($tierPrices)) {
foreach ($tierPrices as $tierPrice) {
if ($tierPrice >= 0) {
return $tierPrice;
}
}
}
return 0.0;
}
}Responsible rules
RemoveUnusedNonEmptyArrayBeforeForeachRector
Expected Behavior
The method getTierPrices return an array or null. This means the if statement can't be removed.