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

PackingListInfo::getPackageAssociated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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
}