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