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 |
||
22 | class WindowsPlatformTest extends TestCase { |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $oldPath; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $oldWorkingDirectory; |
||
32 | |||
33 | /** |
||
34 | * @var WindowsPlatform |
||
35 | */ |
||
36 | protected $platform; |
||
37 | |||
38 | /** |
||
39 | * @inheritdoc TestCase |
||
40 | */ |
||
41 | View Code Duplication | public function setUp() { |
|
50 | |||
51 | /** |
||
52 | * @inheritdoc TestCase |
||
53 | */ |
||
54 | public function tearDown() { |
||
59 | |||
60 | /** |
||
61 | * @covers \ComponentManager\Platform\AbstractPlatform::createTempDirectory |
||
62 | */ |
||
63 | public function testCreateTempDirectory() { |
||
70 | |||
71 | /** |
||
72 | * @covers ::expandPath |
||
73 | */ |
||
74 | public function testExpandPath() { |
||
77 | |||
78 | /** |
||
79 | * @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator |
||
80 | */ |
||
81 | public function testGetDirectorySeparator() { |
||
84 | |||
85 | /** |
||
86 | * @covers ::getExecutablePath |
||
87 | * @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator |
||
88 | * @covers \ComponentManager\Platform\AbstractPlatform::joinPaths |
||
89 | */ |
||
90 | public function testGetExecutablePath() { |
||
95 | |||
96 | /** |
||
97 | * @covers ::getExecutablePath |
||
98 | * @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator |
||
99 | * @covers \ComponentManager\Platform\AbstractPlatform::joinPaths |
||
100 | * |
||
101 | * @expectedException \ComponentManager\Exception\PlatformException |
||
102 | * @expectedExceptionCode 2 |
||
103 | */ |
||
104 | public function testGetExecutablePathThrows() { |
||
107 | |||
108 | /** |
||
109 | * @covers ::getHomeDirectory |
||
110 | */ |
||
111 | public function testGetHomeDirectory() { |
||
118 | |||
119 | /** |
||
120 | * @covers ::getLocalSharedDirectory |
||
121 | */ |
||
122 | public function testGetLocalSharedDirectory() { |
||
125 | |||
126 | /** |
||
127 | * @covers \ComponentManager\Platform\AbstractPlatform::getPhpExecutable |
||
128 | */ |
||
129 | public function testGetPhpExecutable() { |
||
132 | |||
133 | /** |
||
134 | * @covers \ComponentManager\Platform\AbstractPlatform::getPhpScript |
||
135 | */ |
||
136 | public function testGetPhpScript() { |
||
139 | |||
140 | /** |
||
141 | * @covers \ComponentManager\Platform\AbstractPlatform::getWorkingDirectory |
||
142 | */ |
||
143 | public function testGetWorkingDirectory() { |
||
151 | |||
152 | /** |
||
153 | * @covers \ComponentManager\Platform\AbstractPlatform::joinPaths |
||
154 | * @covers \ComponentManager\Platform\AbstractPlatform::getDirectorySeparator |
||
155 | */ |
||
156 | public function testJoinPaths() { |
||
168 | } |
||
169 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.