Completed
Pull Request — master (#86)
by
unknown
03:35
created

AddressKeyFormat   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 86
Duplicated Lines 6.98 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 58.7%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 17
c 4
b 0
f 0
lcom 1
cbo 1
dl 6
loc 86
ccs 27
cts 46
cp 0.587
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSingleLineAddress() 0 4 1
A setSingleLineAddress() 0 4 1
A __construct() 0 10 3
F toNode() 6 43 12

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
8
class AddressKeyFormat extends Address
9
{
10
    /**
11
     * @var string
12
     */
13
    private $singleLineAddress;
14
15
    /**
16
     * @param null|object $attributes
17
     */
18 1
    public function __construct($attributes = null)
19
    {
20 1
        if (null !== $attributes) {
21
            if (isset($attributes->SingleLineAddress)) {
22
                $this->setSingleLineAddress($attributes->SingleLineAddress);
23
            }
24
        }
25
26 1
        parent::__construct($attributes);
27 1
    }
28
29
    /**
30
     * @return string
31
     */
32 1
    public function getSingleLineAddress()
33
    {
34 1
        return $this->singleLineAddress;
35
    }
36
37
    /**
38
     * @param string $singleLineAddress
39
     */
40
    public function setSingleLineAddress($singleLineAddress)
41
    {
42
        $this->singleLineAddress = $singleLineAddress;
43
    }
44
45
    /**
46
     * @param null|DOMDocument $document
47
     *
48
     * @return DOMElement
49
     */
50 1
    public function toNode(DOMDocument $document = null)
51
    {
52 1
        if (null === $document) {
53
            $document = new DOMDocument();
54
        }
55
56 1
        $node = $document->createElement('AddressKeyFormat');
57
58 1
        if ($this->getConsigneeName()) {
59
            $node->appendChild($document->createElement('ConsigneeName', $this->getConsigneeName()));
60
        }
61
62 1
        for ($i = 1; $i <= 3; $i++) {
63 1
            $line = $this->{'getAddressLine' . $i}();
64 1
            if ($line) {
65
                $node->appendChild($document->createElement('AddressLine' . ($i == 1 ? '' : $i), $line));
66
            }
67 1
        }
68
69 1 View Code Duplication
        for ($i = 1; $i <= 3; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
70 1
            $line = $this->{'getPoliticalDivision' . $i}();
71 1
            if ($line) {
72
                $node->appendChild($document->createElement('PoliticalDivision' . $i, $line));
73
            }
74 1
        }
75
76 1
        if ($this->getPostcodePrimaryLow()) {
77 1
            $node->appendChild($document->createElement('PostcodePrimaryLow', $this->getPostcodePrimaryLow()));
78 1
        }
79 1
        if ($this->getPostcodeExtendedLow()) {
80
            $node->appendChild($document->createElement('PostcodeExtendedLow', $this->getPostcodeExtendedLow()));
81
        }
82
83 1
        if ($this->getCountryCode()) {
84 1
            $node->appendChild($document->createElement('CountryCode', $this->getCountryCode()));
85 1
        }
86
87 1
        if ($this->getSingleLineAddress()) {
88
            $node->appendChild($document->createElement('SingleLineAddress', $this->getSingleLineAddress()));
89
        }
90
91 1
        return $node;
92
    }
93
}
94