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 |
||
30 | class news_registryfile |
||
|
|||
31 | { |
||
32 | public $filename; // filename to manage |
||
33 | |||
34 | /** |
||
35 | * @param null $fichier |
||
36 | */ |
||
37 | public function __construct($fichier = null) |
||
38 | { |
||
39 | $this->setfile($fichier); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @param null $fichier |
||
44 | */ |
||
45 | public function setfile($fichier = null) |
||
51 | |||
52 | /** |
||
53 | * @param null $fichier |
||
54 | * |
||
55 | * @return bool|string |
||
56 | */ |
||
57 | public function getfile($fichier = null) |
||
71 | |||
72 | /** |
||
73 | * @param $content |
||
74 | * @param null $fichier |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | public function savefile($content, $fichier = null) |
||
95 | } |
||
96 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.