OrderLineArrayTrait::setOrderLines()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 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 9
    public function getOrderLines() : array
15
    {
16 9
        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 6
    public function setOrderLines(array $orderLines)
24
    {
25 6
        $this->orderLines = $orderLines;
26 6
        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 9
    public function addOrderLine(OrderLineInterface $orderLine) : self
34
    {
35 9
        $this->orderLines[] = $orderLine;
36 9
        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 3
    public function removeOrderLine(OrderLineInterface $orderLine) : self
44
    {
45 3
        foreach ($this->orderLines as $idx => $ol) {
46 3
            if ($orderLine === $ol) {
47 3
                unset($this->orderLines[$idx]);
48 3
                break;
49
            }
50
        }
51 3
        return $this;
52
    }
53
}
54