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

Weight::toNode()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3.576

Importance

Changes 0
Metric Value
dl 18
loc 18
ccs 6
cts 10
cp 0.6
rs 9.6666
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 3.576
1
<?php
2
3
namespace Ups\Entity\Tradeability;
4
5
use DOMDocument;
6
use DOMElement;
7
use Ups\NodeInterface;
8
9
/**
10
 * Class Weight
11
 */
12 View Code Duplication
class Weight 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...
13
{
14
15
    /**
16
     * @var UnitOfMeasurement
17
     */
18
    private $unitOfMeasurement;
19
20
    /**
21
     * @var int
22
     */
23
    private $value;
24
25
    /**
26
     * @param null|DOMDocument $document
27
     *
28
     * @return DOMElement
29
     */
30 1
    public function toNode(DOMDocument $document = null)
31
    {
32 1
        if (null === $document) {
33
            $document = new DOMDocument();
34
        }
35
36 1
        $node = $document->createElement('Weight');
37
38
        // Required
39 1
        $node->appendChild($document->createElement('Value', $this->getValue()));
40
41
        // Optional
42 1
        if ($this->getUnitOfMeasurement() instanceof UnitOfMeasurement) {
43
            $node->appendChild($this->getUnitOfMeasurement()->toNode($document));
44
        }
45
46 1
        return $node;
47
    }
48
49
    /**
50
     * @return int
51
     */
52 1
    public function getValue()
53
    {
54 1
        return $this->value;
55
    }
56
57
    /**
58
     * @param int $value
59
     * @return Quantity
60
     */
61
    public function setValue($value)
62
    {
63
        $this->value = $value;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @return UnitOfMeasurement
70
     */
71 1
    public function getUnitOfMeasurement()
72
    {
73 1
        return $this->unitOfMeasurement;
74
    }
75
76
    /**
77
     * @param UnitOfMeasurement $unitOfMeasurement
78
     * @return Quantity
79
     */
80
    public function setUnitOfMeasurement(UnitOfMeasurement $unitOfMeasurement)
81
    {
82
        $this->unitOfMeasurement = $unitOfMeasurement;
83
84
        return $this;
85
    }
86
}
87