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 |
||
13 | class WidthScalerTest extends TestCase |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @var Filesystem |
||
18 | */ |
||
19 | private $fs; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private $publicPath = './tests/public'; |
||
25 | |||
26 | /** |
||
27 | * @var WidthScaler |
||
28 | */ |
||
29 | private $scaler; |
||
30 | |||
31 | /** |
||
32 | * @var ImageManager |
||
33 | */ |
||
34 | private $engine; |
||
35 | |||
36 | View Code Duplication | public function __construct() { |
|
44 | |||
45 | public function __destruct() { |
||
50 | |||
51 | public function setUp() { |
||
58 | |||
59 | View Code Duplication | public function test_scale_down() { |
|
67 | |||
68 | View Code Duplication | public function test_scale_down_with_max_width() { |
|
79 | |||
80 | private function createSourceFile() { |
||
86 | |||
87 | private function createImageObject() { |
||
92 | |||
93 | } |
||
94 |
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.