Passed
Pull Request — master (#199)
by
unknown
03:18
created

ShipmentTotalWeight::toNode()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 4
nop 1
crap 12
1
<?php
2
3
namespace Ups\Entity;
4
5
use DOMDocument;
6
use DOMElement;
7
use Ups\NodeInterface;
8
use Ups\Entity\UnitOfMeasurement;
9
10
class ShipmentTotalWeight implements NodeInterface
11
{
12
    private $unitOfMeasurement;
13
14
    private $Weight;
15
16 View Code Duplication
    public function __construct($response = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
    {
18
        if (null !== $response) {
19
            if (isset($response->unitOfMeasurement)) {
20
                $this->setUnitOfMeasurement(new UnitOfMeasurement($response->unitOfMeasurement));
21
            }
22
            if (isset($response->Weight)) {
23
                $this->setWeight($response->Weight);
24
            }
25
        }
26
    }
27
28
    /**
29
     * @param null|DOMDocument $document
30
     *
31
     * @return DOMElement
32
     */
33
    public function toNode(DOMDocument $document = null)
34
    {
35
        if (null === $document) {
36
            $document = new DOMDocument();
37
        }
38
39
        $node = $document->createElement('ShipmentTotalWeight');
40
        if ($this->getUnitOfMeasurement()) {
41
            $node->appendChild($this->getUnitOfMeasurement()->toNode($document));
42
        }
43
44
        $node->appendChild($document->createElement('Weight', $this->getWeight()));
45
        
46
        return $node;
47
    }
48
49
    /**
50
     * @return UnitOfMeasurement
51
     */
52
    public function getUnitOfMeasurement()
53
    {
54
        return $this->unitOfMeasurement;
55
    }
56
57
58
    /**
59
     * @param UnitOfMeasurement $unitOfMeasurement
60
     */
61
    public function setUnitOfMeasurement(UnitOfMeasurement $unitOfMeasurement)
62
    {
63
        $this->unitOfMeasurement = $unitOfMeasurement;
64
    }
65
66
    /**
67
     * @return string weight
68
     */
69
    public function getWeight()
70
    {
71
        return $this->Weight;
72
    }
73
    
74
    /**
75
     * @param number $weight
76
     */
77
    public function setWeight($weight)
78
    {
79
        if (!is_numeric($weight)) {
80
            throw new \Exception('Weight value should be a numeric value');
81
        }
82
83
        $this->Weight = $weight;
84
    }
85
}
86