| Conditions | 5 |
| Paths | 5 |
| Total Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function run($request) |
||
| 22 | { |
||
| 23 | $arrayOfBuyables = EcommerceConfig::get('EcommerceDBConfig', 'array_of_buyables'); |
||
| 24 | foreach ($arrayOfBuyables as $buyable) { |
||
|
|
|||
| 25 | $allproducts = $buyable::get(); |
||
| 26 | if ($allproducts->count()) { |
||
| 27 | foreach ($allproducts as $product) { |
||
| 28 | DB::alteration_message('Deleting '.$product->ClassName.' ID = '.$product->ID, 'deleted'); |
||
| 29 | if (is_a($product, Object::getCustomClass('SiteTree'))) { |
||
| 30 | $product->deleteFromStage('Live'); |
||
| 31 | $product->deleteFromStage('Draft'); |
||
| 32 | } else { |
||
| 33 | $product->delete(); |
||
| 34 | } |
||
| 35 | $product->destroy(); |
||
| 36 | //TODO: remove versions |
||
| 37 | } |
||
| 38 | } |
||
| 39 | } |
||
| 40 | } |
||
| 41 | } |
||
| 42 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.