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 |
||
16 | class QueuePurge extends Frame |
||
17 | { |
||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | private $reserved1; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $queue; |
||
27 | |||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | private $noWait; |
||
32 | |||
33 | /** |
||
34 | * @param int $channel |
||
35 | * @param int $reserved1 |
||
36 | * @param string $queue |
||
37 | * @param bool $noWait |
||
38 | */ |
||
39 | public function __construct($channel, $reserved1, $queue, $noWait) |
||
40 | { |
||
41 | $this->reserved1 = $reserved1; |
||
42 | $this->queue = $queue; |
||
43 | $this->noWait = $noWait; |
||
44 | |||
45 | parent::__construct($channel); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Reserved1. |
||
50 | * |
||
51 | * @return int |
||
52 | */ |
||
53 | public function getReserved1() |
||
54 | { |
||
55 | return $this->reserved1; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Queue. |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getQueue() |
||
64 | { |
||
65 | return $this->queue; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * NoWait. |
||
70 | * |
||
71 | * @return bool |
||
72 | */ |
||
73 | public function isNoWait() |
||
74 | { |
||
75 | return $this->noWait; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @return string |
||
80 | */ |
||
81 | public function encode() |
||
82 | { |
||
83 | $data = "\x00\x32\x00\x1E". |
||
84 | Value\ShortValue::encode($this->reserved1). |
||
85 | Value\ShortStringValue::encode($this->queue). |
||
86 | Value\BooleanValue::encode($this->noWait); |
||
87 | |||
88 | return "\x01".pack('nN', $this->channel, strlen($data)).$data."\xCE"; |
||
89 | } |
||
90 | } |
||
91 |