| Total Complexity | 11 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 9 | class LpItemOrderList |
||
| 10 | { |
||
| 11 | public $list = []; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * LpItemOrderList constructor. |
||
| 15 | */ |
||
| 16 | public function __construct() |
||
| 17 | { |
||
| 18 | $this->list = []; |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param int $parentId |
||
| 23 | * |
||
| 24 | * @return LpItemOrderList |
||
| 25 | */ |
||
| 26 | public function getItemWithSameParent($parentId) |
||
| 27 | { |
||
| 28 | $list = new LpItemOrderList(); |
||
| 29 | for ($i = 0; $i < count($this->list); $i++) { |
||
|
|
|||
| 30 | if ($this->list[$i]->parent_item_id == $parentId) { |
||
| 31 | $list->add($this->list[$i]); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | return $list; |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param array $list |
||
| 40 | */ |
||
| 41 | public function add($list) |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return array |
||
| 48 | */ |
||
| 49 | public function getListOfParents() |
||
| 50 | { |
||
| 51 | $result = []; |
||
| 52 | foreach ($this->list as $item) { |
||
| 53 | if (!in_array($item->parent_item_id, $result)) { |
||
| 54 | $result[] = $item->parent_item_id; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | return $result; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @param int $id |
||
| 63 | * @param int $value |
||
| 64 | * @param string $parameter |
||
| 65 | */ |
||
| 66 | public function setParametersForId($id, $value, $parameter) |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: