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 TightTest extends \PHPUnit_Framework_TestCase |
||
35 | { |
||
36 | |||
37 | public $app; |
||
38 | public $config = [ |
||
39 | "basePath" => __DIR__, |
||
40 | "smarty" => [ |
||
41 | "template_dir" => "./templates", |
||
42 | "compile_dir" => "./templates_c", |
||
43 | "config_dir" => "./configs", |
||
44 | "cache_dir" => "./cache" |
||
45 | ], |
||
46 | "router" => [ |
||
47 | "mvc" => [ |
||
48 | "enable" => false, |
||
49 | "index" => "Root", |
||
50 | ] |
||
51 | ], |
||
52 | "mvc" => [ |
||
53 | "enableRouter" => false, |
||
54 | "indexName" => "Root", |
||
55 | "controller_dir" => "./controllers/", |
||
56 | "model_dir" => "./models/", |
||
57 | "view_dir" => "./views/", |
||
58 | ], |
||
59 | "connection" => [ |
||
60 | "user" => "root", |
||
61 | "password" => "root", |
||
62 | "database" => "mysql" |
||
63 | ] |
||
64 | ]; |
||
65 | private $directories = ["res", "controllers", "models", "views"]; |
||
66 | private $files = ["./res/values.json"]; |
||
67 | |||
68 | public function setUp() { |
||
84 | |||
85 | public function tearDown() { |
||
99 | |||
100 | /** |
||
101 | * @test |
||
102 | */ |
||
103 | public function testTightConfig() { |
||
112 | |||
113 | /** |
||
114 | * @test |
||
115 | * @covers Tight\Tight::getRouter |
||
116 | */ |
||
117 | public function testTightGetRouter() { |
||
121 | |||
122 | /** |
||
123 | * @test |
||
124 | */ |
||
125 | public function testTightGetSmarty() { |
||
132 | |||
133 | /** |
||
134 | * @test |
||
135 | */ |
||
136 | public function testTightGetLocale() { |
||
140 | |||
141 | } |
||
142 |
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.