Completed
Pull Request — master (#154)
by
unknown
03:52
created

PackingListInfo   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 30%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 55
ccs 6
cts 20
cp 0.3
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addPackageAssociated() 0 10 1
A getPackageAssociated() 0 4 1
A toNode() 0 17 3
1
<?php
2
3
namespace Ups\Entity;
4
5
use DOMDocument;
6
use Ups\NodeInterface;
7
8
/**
9
 * @author Thijs Wijnmaalen <[email protected]>
10
 */
11
class PackingListInfo implements NodeInterface
12
{
13
    /**
14
     * @var array
15
     */
16
    private $packageAssociated = [];
17
18
    /**
19
     * @param string $number
20
     * @param string $amount
21
     *
22
     * @return $this
23
     */
24
    public function addPackageAssociated($number, $amount)
25
    {
26
        $object = new \stdClass();
27
        $object->PackageNumber = $number;
28
        $object->ProductAmount = $amount;
29
30
        $this->packageAssociated[] = $object;
31
32
        return $this;
33
    }
34
35
    /**
36
     * @return $this
37
     */
38
    public function getPackageAssociated()
39
    {
40
        return $this->packageAssociated;
41
    }
42
43
    /**
44
     * @param null|DOMDocument $document
45
     *
46
     * @return DOMElement
47
     */
48 1
    public function toNode(DOMDocument $document = null)
49
    {
50 1
        if (null === $document) {
51
            $document = new DOMDocument();
52
        }
53
54 1
        $node = $document->createElement('PackingListInfo');
55
56 1
        foreach ($this->packageAssociated as $object) {
57
            $packageAssociated = $document->createElement('PackageAssociated');
58
            $packageAssociated->appendChild($document->createElement('PackageNumber', $object->PackageNumber));
59
            $packageAssociated->appendChild($document->createElement('ProductAmount', $object->ProductAmount));
60
            $node->appendChild($packageAssociated);
61 1
        }
62
63 1
        return $node;
64
    }
65
}