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 ChannelFlow extends Frame |
||
17 | { |
||
18 | /** |
||
19 | * @var bool |
||
20 | */ |
||
21 | private $active; |
||
22 | |||
23 | /** |
||
24 | * @param int $channel |
||
25 | * @param bool $active |
||
26 | */ |
||
27 | public function __construct($channel, $active) |
||
28 | { |
||
29 | $this->active = $active; |
||
30 | |||
31 | parent::__construct($channel); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Start/stop content frames. |
||
36 | * |
||
37 | * @return bool |
||
38 | */ |
||
39 | public function isActive() |
||
40 | { |
||
41 | return $this->active; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return string |
||
46 | */ |
||
47 | public function encode() |
||
48 | { |
||
49 | $data = "\x00\x14\x00\x14". |
||
50 | Value\BooleanValue::encode($this->active); |
||
51 | |||
52 | return "\x01".pack('nN', $this->channel, strlen($data)).$data."\xCE"; |
||
53 | } |
||
54 | } |
||
55 |