Segment   A
last analyzed

Complexity

Total Complexity 41

Size/Duplication

Total Lines 261
Duplicated Lines 9.2 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 41
lcom 1
cbo 1
dl 24
loc 261
rs 9.1199
c 0
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getSegmentId() 0 4 1
A getSegmentName() 0 4 1
A setSegmentName() 0 4 1
A getSegmentStatus() 0 4 1
A getDescription() 0 4 1
A setDescription() 0 4 1
A getIntegrationCode() 0 4 1
A setIntegrationCode() 0 4 1
A getAccountUserListStatus() 0 4 1
A setAccountUserListStatus() 0 4 1
A getAccessReason() 0 4 1
A setAccessReason() 0 4 1
A getisEligibleForSearch() 0 4 1
A setIsEligibleForSearch() 0 4 1
A getMembershipLifeSpan() 0 4 1
A setMembershipLifeSpan() 0 4 1
A getListType() 0 4 1
A setListType() 0 4 1
A getSize() 0 4 1
A setSize() 0 4 1
F fromArray() 24 52 20

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Segment often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Segment, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Audiens\DoubleclickClient\entity;
4
5
use Audiens\DoubleclickClient\exceptions\ClientException;
6
7
class Segment
8
{
9
    /** @var int */
10
    protected $segmentId;
11
12
    /** @var string */
13
    protected $segmentName;
14
15
    /** @var string */
16
    protected $segmentStatus;
17
18
    /** @var null|string */
19
    protected $description;
20
21
    /** @var null|string */
22
    protected $integrationCode;
23
24
    /** @var null|string */
25
    protected $accountUserListStatus;
26
27
    /** @var null */
28
    protected $accessReason;
29
30
    /** @var null */
31
    protected $isEligibleForSearch;
32
33
    /** @var null */
34
    protected $membershipLifeSpan;
35
36
    /** @var string */
37
    protected $listType;
38
39
    /** @var string */
40
    protected $size;
41
42
    public function __construct($segmentId, $segmentName, $segmentStatus, $description = null, $integrationCode = null, $accountUserListStatus = null, $accessReason = null, $isEligibleForSearch = null, $membershipLifeSpan = null)
43
    {
44
        $this->segmentId             = $segmentId;
45
        $this->segmentName           = $segmentName;
46
        $this->segmentStatus         = $segmentStatus;
47
        $this->description           = $description;
48
        $this->integrationCode       = $integrationCode;
49
        $this->accountUserListStatus = $accountUserListStatus;
50
        $this->accessReason          = $accessReason;
51
        $this->isEligibleForSearch   = $isEligibleForSearch;
52
        $this->membershipLifeSpan    = $membershipLifeSpan;
53
    }
54
55
    /**
56
     * @return int
57
     */
58
    public function getSegmentId()
59
    {
60
        return $this->segmentId;
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function getSegmentName()
67
    {
68
        return $this->segmentName;
69
    }
70
71
    /**
72
     * @param $name
73
     */
74
    public function setSegmentName($name)
75
    {
76
        $this->segmentName = $name;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getSegmentStatus()
83
    {
84
        return $this->segmentStatus;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getDescription()
91
    {
92
        return $this->description;
93
    }
94
95
    /**
96
     * @param string $description
97
     */
98
    public function setDescription($description)
99
    {
100
        $this->description = $description;
101
    }
102
103
    /**
104
     * @return string
105
     */
106
    public function getIntegrationCode()
107
    {
108
        return $this->integrationCode;
109
    }
110
111
    /**
112
     * @param string $integrationCode
113
     */
114
    public function setIntegrationCode($integrationCode)
115
    {
116
        $this->integrationCode = $integrationCode;
117
    }
118
119
    /**
120
     * @return string
121
     */
122
    public function getAccountUserListStatus()
123
    {
124
        return $this->accountUserListStatus;
125
    }
126
127
    /**
128
     * @param string $accountUserListStatus
129
     */
130
    public function setAccountUserListStatus($accountUserListStatus)
131
    {
132
        $this->accountUserListStatus = $accountUserListStatus;
133
    }
134
135
    /**
136
     * @return mixed
137
     */
138
    public function getAccessReason()
139
    {
140
        return $this->accessReason;
141
    }
142
143
    /**
144
     * @param mixed $accessReason
145
     */
146
    public function setAccessReason($accessReason)
147
    {
148
        $this->accessReason = $accessReason;
149
    }
150
151
    /**
152
     * @return mixed
153
     */
154
    public function getisEligibleForSearch()
155
    {
156
        return $this->isEligibleForSearch;
157
    }
158
159
    /**
160
     * @param mixed $isEligibleForSearch
161
     */
162
    public function setIsEligibleForSearch($isEligibleForSearch)
163
    {
164
        $this->isEligibleForSearch = $isEligibleForSearch;
165
    }
166
167
    /**
168
     * @return mixed
169
     */
170
    public function getMembershipLifeSpan()
171
    {
172
        return $this->membershipLifeSpan;
173
    }
174
175
    /**
176
     * @param mixed $membershipLifeSpan
177
     */
178
    public function setMembershipLifeSpan($membershipLifeSpan)
179
    {
180
        $this->membershipLifeSpan = $membershipLifeSpan;
181
    }
182
183
    /**
184
     * @return mixed
185
     */
186
    public function getListType()
187
    {
188
        return $this->listType;
189
    }
190
191
    /**
192
     * @param  $listType
193
     */
194
    public function setListType($listType)
195
    {
196
        $this->listType = $listType;
197
    }
198
199
    /**
200
     * @return mixed
201
     */
202
    public function getSize()
203
    {
204
        return $this->size;
205
    }
206
207
    /**
208
     * @param mixed $size
209
     */
210
    public function setSize($size)
211
    {
212
        $this->size = $size;
213
    }
214
215
    public static function fromArray(array $array)
216
    {
217
        if (!isset($array['id'])) {
218
            throw ClientException::validation('hydration: id');
219
        }
220
221
        if (!isset($array['name'])) {
222
            throw ClientException::validation('hydration: name');
223
        }
224
225
        if (!isset($array['status'])) {
226
            throw ClientException::validation('hydration: status');
227
        }
228
229
        $segment = new self(
230
            $array['id'],
231
            $array['name'],
232
            $array['status']
233
        );
234
235 View Code Duplication
        if (isset($array['description']) && !is_array($array['description'])) {
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...
236
            $segment->setDescription($array['description']);
237
        }
238
239 View Code Duplication
        if (isset($array['accountuserliststatus']) && !is_array($array['accountuserliststatus'])) {
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...
240
            $segment->setAccountUserListStatus($array['accountuserliststatus']);
241
        }
242 View Code Duplication
        if (isset($array['accessreason']) && !is_array($array['accessreason'])) {
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...
243
            $segment->setAccessReason($array['accessreason']);
244
        }
245
246 View Code Duplication
        if (isset($array['iseligibleforsearch']) && !is_array($array['iseligibleforsearch'])) {
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...
247
            $segment->setIsEligibleForSearch($array['iseligibleforsearch']);
248
        }
249 View Code Duplication
        if (isset($array['membershiplifespan']) && !is_array($array['membershiplifespan'])) {
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...
250
            $segment->setMembershipLifeSpan($array['membershiplifespan']);
251
        }
252
253 View Code Duplication
        if (isset($array['listtype']) && !is_array($array['listtype'])) {
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...
254
            $segment->setListType($array['listtype']);
255
        }
256
257 View Code Duplication
        if (isset($array['size']) && !is_array($array['size'])) {
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...
258
            $segment->setSize($array['size']);
259
        }
260
261 View Code Duplication
        if (isset($array['integrationcode']) && !is_array($array['integrationcode'])) {
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...
262
            $segment->setIntegrationCode($array['integrationcode']);
263
        }
264
265
        return $segment;
266
    }
267
}
268