Completed
Pull Request — master (#199)
by
unknown
11:08
created

ShipmentTotalWeight::__construct()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 0
cts 10
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 5
nop 1
crap 20
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
    private $Weight;
14
15 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...
16
    {
17
        if (null !== $response) {
18
            if (isset($response->unitOfMeasurement)) {
19
                $this->setUnitOfMeasurement($response->unitOfMeasurement);
20
            }
21
            if (isset($response->Weight)) {
22
                $this->setWeight($response->Weight);
23
            }
24
        }
25
    }
26
27
    /**
28
     * @param null|DOMDocument $document
29
     *
30
     * @return DOMElement
31
     */
32
    public function toNode(DOMDocument $document = null)
33
    {
34
        if (null === $document) {
35
            $document = new DOMDocument();
36
        }
37
38
        $node = $document->createElement('ShipmentTotalWeight');
39
        if ($this->getUnitOfMeasurement()) {
40
            $node->appendChild($this->getUnitOfMeasurement()->toNode($document));
41
        }
42
43
        $node->appendChild($document->createElement('Weight', $this->getWeight()));
44
        
45
        return $node;
46
    }
47
48
    /**
49
     * @return UnitOfMeasurement unitOfMeasurement
50
     */
51
    public function getUnitOfMeasurement()
52
    {
53
        return $this->unitOfMeasurement;
54
    }
55
56
57
    /**
58
     * @param UnitOfMeasurement $unitOfMeasurement
59
     */
60
    public function setUnitOfMeasurement( UnitOfMeasurement $unitOfMeasurement)
61
    {
62
        $this->unitOfMeasurement = $unitOfMeasurement;
63
    }
64
65
    /**
66
     * @return weight
67
     */
68
    public function getWeight()
69
    {
70
        return $this->Weight;
71
    }
72
    
73
    /**
74
     * @param number $weight
75
     */
76
    public function setWeight($weight)
77
    {
78
        if (!is_numeric($weight)) {
79
            throw new \Exception('Weight value should be a numeric value');
80
        }
81
82
        $this->Weight = $weight;
83
    }
84
}
85