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

ShipmentTotalWeight   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 76
Duplicated Lines 14.47 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
lcom 1
cbo 1
dl 11
loc 76
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
    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