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 |
||
| 20 | class FakeManager { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * |
||
| 24 | * @var type |
||
| 25 | */ |
||
| 26 | protected $db; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * |
||
| 30 | * @var type |
||
| 31 | */ |
||
| 32 | protected $addressRightGateway; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * |
||
| 36 | * @param FakeDatabase $db |
||
| 37 | */ |
||
| 38 | View Code Duplication | function __construct($db = null) { |
|
| 47 | |||
| 48 | public function setDb($db) { |
||
| 54 | } |
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.