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 |
||
| 22 | class Table implements TableInterface |
||
| 23 | { |
||
| 24 | use ScalarParserTrait; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string A buffer containing the table data. |
||
| 28 | */ |
||
| 29 | private $buffer = ''; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Retrieve the next frame from the internal buffer. |
||
| 33 | * |
||
| 34 | * @param string &$buffer Binary data containing the table. |
||
| 35 | * |
||
| 36 | * @throws AMQPProtocolException if the incoming data does not conform to the |
||
| 37 | * AMQP specification. |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | public function parse(&$buffer) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Parse an AMQP table from the head of the buffer. |
||
| 49 | * @return array |
||
| 50 | * @throws \PHPDaemon\Clients\AMQP\Driver\Protocol\Exception\AMQPProtocolException |
||
| 51 | */ |
||
| 52 | View Code Duplication | private function parseTable() |
|
| 64 | |||
| 65 | /** |
||
| 66 | * Parse a table or array field. |
||
| 67 | * |
||
| 68 | * @return integer|array|boolean|double|string|null |
||
| 69 | * @throws AMQPProtocolException |
||
| 70 | */ |
||
| 71 | private function parseField() |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Parse an AMQP decimal from the head of the buffer. |
||
| 118 | * @return string |
||
| 119 | */ |
||
| 120 | public function parseDecimal() |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Parse an AMQP field-array value. |
||
| 152 | * @return array |
||
| 153 | * @throws \PHPDaemon\Clients\AMQP\Driver\Protocol\Exception\AMQPProtocolException |
||
| 154 | */ |
||
| 155 | View Code Duplication | private function parseArray() |
|
| 167 | |||
| 168 | /** |
||
| 169 | * Parse an AMQP byte-array value. |
||
| 170 | * @return array |
||
| 171 | */ |
||
| 172 | View Code Duplication | private function parseByteArray() |
|
| 182 | } |
||
| 183 |
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.