Completed
Pull Request — master (#197)
by
unknown
04:20 queued 25s
created

ShipmentTotalWeight   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 62
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 4
A toNode() 15 15 3
A getUnitOfMeasurement() 4 4 1
A setUnitOfMeasurement() 4 4 1
A getWeight() 4 4 1
A setWeight() 8 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
9 View Code Duplication
class ShipmentTotalWeight implements NodeInterface
0 ignored issues
show
Duplication introduced by
This class 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...
10
{
11
    private $UnitOfMeasurement;
12
    private $Weight;
13
14
    public function __construct($response = null)
15
    {
16
        if (null !== $response) {
17
            if (isset($response->UnitOfMeasurement)) {
18
                $this->setUnitOfMeasurement($response->UnitOfMeasurement);
19
            }
20
            if (isset($response->Weight)) {
21
                $this->setWeight($response->Weight);
22
            }
23
        }
24
    }
25
26
    /**
27
     * @param null|DOMDocument $document
28
     *
29
     * @return DOMElement
30
     */
31
    public function toNode(DOMDocument $document = null)
32
    {
33
        if (null === $document) {
34
            $document = new DOMDocument();
35
        }
36
37
        $node = $document->createElement('ShipmentTotalWeight');
38
        if ($this->getUnitOfMeasurement()) {
39
            $node->appendChild($this->getUnitOfMeasurement()->toNode($document));
40
        }
41
42
        $node->appendChild($document->createElement('Weight', $this->getWeight()));
43
        
44
        return $node;
45
    }
46
47
    public function getUnitOfMeasurement()
48
    {
49
        return $this->UnitOfMeasurement;
50
    }
51
52
    public function setUnitOfMeasurement($var)
53
    {
54
        $this->UnitOfMeasurement = $var;
55
    }
56
57
    public function getWeight()
58
    {
59
        return $this->Weight;
60
    }
61
62
    public function setWeight($var)
63
    {
64
        if (!is_numeric($var)) {
65
            throw new \Exception('Weight value should be a numeric value');
66
        }
67
68
        $this->Weight = $var;
69
    }
70
}
71