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 |
||
34 | class TightConfig |
||
35 | { |
||
36 | |||
37 | /** |
||
38 | * @var string Application base path |
||
39 | */ |
||
40 | public $basePath = null; |
||
41 | |||
42 | /** |
||
43 | * @var array Smarty settings |
||
44 | */ |
||
45 | public $smarty = [ |
||
46 | "template_dir" => "./templates", |
||
47 | "compile_dir" => "./templates_c", |
||
48 | "config_dir" => "./configs", |
||
49 | "cache_dir" => "./cache" |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * @var array Router settings |
||
54 | */ |
||
55 | public $router = [ |
||
56 | "mvc" => [ |
||
57 | "enable" => false, |
||
58 | "index" => "Root", |
||
59 | ] |
||
60 | ]; |
||
61 | |||
62 | /** |
||
63 | * @var array MVC settings |
||
64 | */ |
||
65 | public $mvc = [ |
||
66 | "enaleRouter" => false, |
||
67 | "indexName"=> "Root", |
||
68 | "controller_dir" => "./controllers/", |
||
69 | "model_dir" => "./models/", |
||
70 | "view_dir" => "./views/", |
||
71 | ]; |
||
72 | |||
73 | /** |
||
74 | * Constructor |
||
75 | * |
||
76 | * Settings can be passed as an array |
||
77 | * @param array $config Settings |
||
78 | */ |
||
79 | public function __construct(array $config = []) { |
||
103 | |||
104 | } |
||
105 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.