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

ShipmentTotalWeight::setWeight()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
90
    }
91
}