Completed
Push — master ( 3ee5ff...5084e8 )
by Joachim
12:38
created

OrderLineArrayTrait::removeOrderLine()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
namespace Loevgaard\AltaPay\Payload;
3
4
trait OrderLineArrayTrait
5
{
6
    /**
7
     * @var OrderLineInterface[]
8
     */
9
    private $orderLines;
10
11
    /**
12
     * @return OrderLineInterface[]
13
     */
14
    public function getOrderLines() : array
15
    {
16
        return $this->orderLines;
17
    }
18
19
    /**
20
     * @param OrderLine[] $orderLines
21
     * @return OrderLineArrayTrait
0 ignored issues
show
Comprehensibility Bug introduced by
The return type OrderLineArrayTrait is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
22
     */
23
    public function setOrderLines(array $orderLines)
24
    {
25
        $this->orderLines = $orderLines;
26
        return $this;
27
    }
28
29
    /**
30
     * @param OrderLineInterface $orderLine
31
     * @return OrderLineArrayTrait
0 ignored issues
show
Comprehensibility Bug introduced by
The return type OrderLineArrayTrait is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
32
     */
33
    public function addOrderLine(OrderLineInterface $orderLine) : self
34
    {
35
        $this->orderLines[] = $orderLine;
36
        return $this;
37
    }
38
39
    /**
40
     * @param OrderLineInterface $orderLine
41
     * @return OrderLineArrayTrait
0 ignored issues
show
Comprehensibility Bug introduced by
The return type OrderLineArrayTrait is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
42
     */
43
    public function removeOrderLine(OrderLineInterface $orderLine) : self
44
    {
45
        foreach ($this->orderLines as $idx => $ol) {
46
            if ($orderLine === $ol) {
47
                unset($this->orderLines[$idx]);
48
                break;
49
            }
50
        }
51
        return $this;
52
    }
53
}
54