Passed
Pull Request — master (#223)
by
unknown
02:52
created

UnitPrice   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 24 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 18
loc 75
ccs 10
cts 20
cp 0.5
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getMonetaryValue() 0 4 1
A getCurrencyCode() 0 4 1
A toNode() 18 18 3
A setMonetaryValue() 0 6 1
A setCurrencyCode() 0 6 1

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\Tradeability;
4
5
use DOMDocument;
6
use DOMElement;
7
use Ups\NodeInterface;
8
9
/**
10
 * Class UnitPrice.
11
 */
12
class UnitPrice implements NodeInterface
13
{
14
15
    /**
16
     * @var float
17
     */
18
    private $monetaryValue;
19
20
    /**
21
     * @var string
22
     */
23
    private $currencyCode;
24
25
    /**
26
     * @param null|DOMDocument $document
27
     *
28
     * @return DOMElement
29
     */
30 1 View Code Duplication
    public function toNode(DOMDocument $document = 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...
31
    {
32 1
        if (null === $document) {
33
            $document = new DOMDocument();
34
        }
35
36 1
        $node = $document->createElement('UnitPrice');
37
38
        // Required
39 1
        $node->appendChild($document->createElement('MonetaryValue', $this->getMonetaryValue()));
40
41
        // Optional
42 1
        if ($this->getCurrencyCode() !== null) {
43
            $node->appendChild($document->createElement('CurrencyCode', $this->getCurrencyCode()));
44
        }
45
46 1
        return $node;
47
    }
48
49
    /**
50
     * @return float
51
     */
52 1
    public function getMonetaryValue()
53
    {
54 1
        return $this->monetaryValue;
55
    }
56
57
    /**
58
     * @param float $monetaryValue
59
     * @return UnitPrice
60
     */
61
    public function setMonetaryValue($monetaryValue)
62
    {
63
        $this->monetaryValue = $monetaryValue;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @return string
70
     */
71 1
    public function getCurrencyCode()
72
    {
73 1
        return $this->currencyCode;
74
    }
75
76
    /**
77
     * @param string $currencyCode
78
     * @return UnitPrice
79
     */
80
    public function setCurrencyCode($currencyCode)
81
    {
82
        $this->currencyCode = $currencyCode;
83
84
        return $this;
85
    }
86
}
87