OrderLineArrayTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 50
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getOrderLines() 0 4 1
A setOrderLines() 0 5 1
A addOrderLine() 0 5 1
A removeOrderLine() 0 10 3
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