Test Failed
Pull Request — master (#196)
by
unknown
02:46
created

ShipmentTotalWeight   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 63
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 12
c 0
b 0
f 0
lcom 1
cbo 0
dl 63
loc 63
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 4
A toNode() 16 16 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
           // $node->appendChild($document->createElement('UnitOfMeasurement', $this->getUnitOfMeasurement()));
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
        }
42
43
        $node->appendChild($document->createElement('Weight', $this->getWeight()));
44
        
45
        return $node;
46
    }
47
48
    public function getUnitOfMeasurement()
49
    {
50
        return $this->UnitOfMeasurement;
51
    }
52
53
    public function setUnitOfMeasurement($var)
54
    {
55
        $this->UnitOfMeasurement = $var;
56
    }
57
58
    public function getWeight()
59
    {
60
        return $this->Weight;
61
    }
62
63
    public function setWeight($var)
64
    {
65
        if (!is_numeric($var)) {
66
            throw new \Exception('Weight value should be a numeric value');
67
        }
68
69
        $this->Weight = $var;
70
    }
71
}
72