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 |
||
| 6 | class GenericMessage implements MessageInterface |
||
| 7 | { |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @var array |
||
| 11 | */ |
||
| 12 | protected $params; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var String |
||
| 16 | */ |
||
| 17 | protected $command; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var String |
||
| 21 | */ |
||
| 22 | protected $prefix; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var ConnectionInterface |
||
| 26 | */ |
||
| 27 | protected $connection; |
||
| 28 | |||
| 29 | View Code Duplication | function __construct($command, $prefix = "", array $params = array(), $connection = null) |
|
| 36 | |||
| 37 | /** |
||
| 38 | * @return ConnectionInterface |
||
| 39 | */ |
||
| 40 | public function getConnection() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param ConnectionInterface $connection |
||
| 47 | * @return void |
||
| 48 | */ |
||
| 49 | public function setConnection(ConnectionInterface $connection) |
||
| 53 | |||
| 54 | public function getRaw() |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @return string |
||
| 79 | */ |
||
| 80 | public function getCommand() |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @return string |
||
| 87 | */ |
||
| 88 | public function getPrefix() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param string $prefix |
||
| 95 | * @return void |
||
| 96 | */ |
||
| 97 | public function setPrefix($prefix) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @return array |
||
| 104 | */ |
||
| 105 | public function getParams() |
||
| 109 | |||
| 110 | } |
||
| 111 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.