Completed
Push — master ( fd90eb...52b814 )
by Stefan
04:00
created

PackageWeight::getWeight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Ups\Entity;
4
5
use DOMDocument;
6
use DOMElement;
7
use Ups\NodeInterface;
8
9
class PackageWeight implements NodeInterface
10
{
11
    /** @deprecated */
12
    public $UnitOfMeasurement;
13
14
    /** @deprecated */
15
    public $Weight;
16
17
    /**
18
     * @var UnitOfMeasurement
19
     */
20
    private $unitOfMeasurement;
21
22
    /**
23
     * @var string
24
     */
25
    private $weight;
26
27 2
    public function __construct($attributes = null)
28
    {
29 2
        $this->setUnitOfMeasurement(new UnitOfMeasurement(
30 2
            isset($attributes->UnitOfMeasurement) ? $attributes->UnitOfMeasurement : null
31 2
        ));
32 2
        if (isset($attributes->Weight)) {
33
            $this->setWeight($attributes->Weight);
34
        }
35 2
    }
36
37
    /**
38
     * @param null|DOMDocument $document
39
     *
40
     * @return DOMElement
41
     */
42 2
    public function toNode(DOMDocument $document = null)
43
    {
44 2
        if (null === $document) {
45
            $document = new DOMDocument();
46
        }
47
48 2
        $node = $document->createElement('PackageWeight');
49 2
        $node->appendChild($document->createElement('Weight', $this->getWeight()));
50 2
        $node->appendChild($this->getUnitOfMeasurement()->toNode($document));
51
52 2
        return $node;
53
    }
54
55
    /**
56
     * @return UnitOfMeasurement
57
     */
58 2
    public function getUnitOfMeasurement()
59
    {
60 2
        return $this->unitOfMeasurement;
61
    }
62
63
    /**
64
     * @param UnitOfMeasurement $unitOfMeasurement
65
     *
66
     * @return $this
67
     */
68 2
    public function setUnitOfMeasurement(UnitOfMeasurement $unitOfMeasurement)
69
    {
70 2
        $this->UnitOfMeasurement = $unitOfMeasurement;
0 ignored issues
show
Deprecated Code introduced by
The property Ups\Entity\PackageWeight::$UnitOfMeasurement has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
71 2
        $this->unitOfMeasurement = $unitOfMeasurement;
72
73 2
        return $this;
74
    }
75
76
    /**
77
     * @return string
78
     */
79 2
    public function getWeight()
80
    {
81 2
        return $this->weight;
82
    }
83
84
    /**
85
     * @param string $weight
86
     *
87
     * @return $this
88
     */
89
    public function setWeight($weight)
90
    {
91
        $this->Weight = $weight;
0 ignored issues
show
Deprecated Code introduced by
The property Ups\Entity\PackageWeight::$Weight has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
92
        $this->weight = $weight;
93
94
        return $this;
95
    }
96
}
97