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 |
||
6 | class ListQueueRequest extends BaseRequest |
||
7 | { |
||
8 | private $retNum; |
||
9 | private $prefix; |
||
10 | private $marker; |
||
11 | |||
12 | public function __construct($retNum = NULL, $prefix = NULL, $marker = NULL) |
||
13 | { |
||
14 | parent::__construct('get', 'queues'); |
||
15 | |||
16 | $this->setRetNum($retNum); |
||
17 | $this->setPrefix($prefix); |
||
18 | $this->setMarker($marker); |
||
19 | } |
||
20 | |||
21 | public function getRetNum() |
||
22 | { |
||
23 | return $this->retNum; |
||
24 | } |
||
25 | |||
26 | public function setRetNum($retNum) |
||
27 | { |
||
28 | $this->retNum = $retNum; |
||
29 | if ($retNum != NULL) |
||
30 | { |
||
31 | $this->setHeader("x-mns-ret-number", $retNum); |
||
32 | } |
||
33 | else |
||
34 | { |
||
35 | $this->removeHeader("x-mns-ret-number"); |
||
36 | } |
||
37 | } |
||
38 | |||
39 | public function getPrefix() |
||
40 | { |
||
41 | return $this->prefix; |
||
42 | } |
||
43 | |||
44 | public function setPrefix($prefix) |
||
45 | { |
||
46 | $this->prefis = $prefix; |
||
47 | if ($prefix != NULL) |
||
48 | { |
||
49 | $this->setHeader("x-mns-prefix", $prefix); |
||
50 | } |
||
51 | else |
||
52 | { |
||
53 | $this->removeHeader("x-mns-prefix"); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | public function getMarker() |
||
58 | { |
||
59 | return $this->marker; |
||
60 | } |
||
61 | |||
62 | public function setMarker($marker) |
||
63 | { |
||
64 | $this->marker = $marker; |
||
65 | if ($marker != NULL) |
||
66 | { |
||
67 | $this->setHeader("x-mns-marker", $marker); |
||
68 | } |
||
69 | else |
||
70 | { |
||
71 | $this->removeHeader("x-mns-marker"); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | public function generateBody() |
||
76 | { |
||
77 | return NULL; |
||
78 | } |
||
79 | |||
80 | public function generateQueryString() |
||
81 | { |
||
82 | return NULL; |
||
83 | } |
||
84 | } |
||
85 | |||
87 |