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 |
||
24 | class FakeManager { |
||
25 | |||
26 | /** |
||
27 | * |
||
28 | * @var type |
||
29 | */ |
||
30 | protected $db; |
||
31 | |||
32 | /** |
||
33 | * |
||
34 | * @var type |
||
35 | */ |
||
36 | protected $addressRightGateway; |
||
37 | |||
38 | /** |
||
39 | * |
||
40 | * @param FakeDatabase $db |
||
41 | */ |
||
42 | View Code Duplication | function __construct($db = null) { |
|
51 | |||
52 | public function setDb($db) { |
||
58 | } |
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.