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

ShipmentTotalWeight   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 82
Duplicated Lines 13.41 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 12
c 2
b 1
f 0
lcom 1
cbo 1
dl 11
loc 82
ccs 0
cts 32
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 4
A toNode() 0 15 3
A getUnitOfMeasurement() 0 4 1
A setUnitOfMeasurement() 0 4 1
A getWeight() 0 4 1
A setWeight() 0 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}