Passed
Push — master ( 0539c1...988ac6 )
by Julito
09:19
created

LpItemOrderList::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
eloc 1
c 1
b 1
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Class LpItemOrderList.
6
 *
7
 * Classes to create a special data structure to manipulate LP Items used only in this file.
8
 */
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++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

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:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
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)
42
    {
43
        $this->list[] = $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)
67
    {
68
        for ($i = 0; $i < count($this->list); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

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:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
69
            if ($this->list[$i]->id == $id) {
70
                $this->list[$i]->$parameter = $value;
71
                break;
72
            }
73
        }
74
    }
75
}
76