Option   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 108
Duplicated Lines 19.44 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 21
loc 108
ccs 0
cts 47
cp 0
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromXML() 21 21 3
A getVisibility() 0 4 1
A setVisibility() 0 4 1
A getPrice() 0 4 1
A setPrice() 0 4 1
A getName() 0 4 1
A setName() 0 4 1
A getCharacteristics() 0 4 1
A addCharacteristic() 0 4 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 Bpost\BpostApiClient\Bpost\ProductConfiguration;
4
5
use SimpleXMLElement;
6
7
/**
8
 * Class Option
9
 * @package Bpost\BpostApiClient\Bpost\ProductConfiguration
10
 */
11
class Option
12
{
13
14
    const OPTION_VISIBILITY_NOT_VISIBLE_BY_CONSUMER_OPTIONAL = 'NOT_VISIBLE_BY_CONSUMER_OPTIONAL';
15
    const OPTION_VISIBILITY_NOT_VISIBLE_BY_CONSUMER_DEFAULT = 'NOT_VISIBLE_BY_CONSUMER_DEFAULT';
16
    const OPTION_VISIBILITY_VISIBLE_BY_CONSUMER_AND_MANDATORY = 'VISIBLE_BY_CONSUMER_AND_MANDATORY';
17
18
    /** @var  string */
19
    private $visibility;
20
    /** @var  int */
21
    private $price;
22
    /** @var  string */
23
    private $name;
24
    /** @var Characteristic[] */
25
    private $characteristics = array();
26
27
    /**
28
     * @param SimpleXMLElement $xml
29
     *
30
     * @return Option
31
     */
32 View Code Duplication
    public static function createFromXML(SimpleXMLElement $xml)
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...
33
    {
34
        /*
35
        <option visiblity="NOT_VISIBLE_BY_CONSUMER_OPTIONAL" price="0" name="Cash on delivery"/>
36
        */
37
        $attributes = $xml->attributes();
38
        $children = $xml->children();
39
40
        $option = new self();
41
        $option->setVisibility($attributes['visiblity']);
42
        $option->setPrice($attributes['price']);
43
        $option->setName($attributes['name']);
44
45
        if (isset($children->chracteristic)) {
46
            foreach ($children->chracteristic as $characteristicXml) {
47
                $option->addCharacteristic(Characteristic::createFromXML($characteristicXml));
48
            }
49
        }
50
51
        return $option;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getVisibility()
58
    {
59
        return $this->visibility;
60
    }
61
62
    /**
63
     * @param string $visibility
64
     */
65
    public function setVisibility($visibility)
66
    {
67
        $this->visibility = (string) $visibility;
68
    }
69
70
    /**
71
     * @return int
72
     */
73
    public function getPrice()
74
    {
75
        return $this->price;
76
    }
77
78
    /**
79
     * @param int $price
80
     */
81
    public function setPrice($price)
82
    {
83
        $this->price = (int) $price;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getName()
90
    {
91
        return $this->name;
92
    }
93
94
    /**
95
     * @param string $name
96
     */
97
    public function setName($name)
98
    {
99
        $this->name = (string) $name;
100
    }
101
102
    /**
103
     * @return Characteristic[]
104
     */
105
    public function getCharacteristics()
106
    {
107
        return $this->characteristics;
108
    }
109
110
    /**
111
     * @param Characteristic $characteristic
112
     */
113
    public function addCharacteristic(Characteristic $characteristic)
114
    {
115
        $this->characteristics[] = $characteristic;
116
    }
117
118
}
119