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 BlockCollection extends Collection |
||
| 17 | { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Collection constructor |
||
| 21 | * |
||
| 22 | * @throws InvalidInterfaceException |
||
| 23 | */ |
||
| 24 | public function __construct() |
||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * unRegisterBlock |
||
| 32 | * finds block in the Collection based on the identifier that was set using addObject() |
||
| 33 | * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found. |
||
| 34 | * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
||
| 35 | * |
||
| 36 | * @param mixed $identifier |
||
| 37 | * @return boolean |
||
| 38 | */ |
||
| 39 | View Code Duplication | public function unRegisterBlock($identifier) |
|
| 52 | |||
| 53 | |||
| 54 | /** |
||
| 55 | * unRegisterAllBlocks |
||
| 56 | * calls unRegisterBlock() on all blocks in Collection. |
||
| 57 | * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
||
| 58 | * |
||
| 59 | * @return void |
||
| 60 | */ |
||
| 61 | public function unRegisterAllBlocks() |
||
| 70 | } |
||
| 71 |