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 |
||
12 | class FileSizeScalerTest extends TestCase |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @var Filesystem |
||
17 | */ |
||
18 | private $fs; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $publicPath = './tests/public'; |
||
24 | |||
25 | /** |
||
26 | * @var FileSizeScaler |
||
27 | */ |
||
28 | private $scaler; |
||
29 | |||
30 | /** |
||
31 | * @var ImageManager |
||
32 | */ |
||
33 | private $engine; |
||
34 | |||
35 | View Code Duplication | public function __construct() { |
|
43 | |||
44 | public function __destruct() { |
||
49 | |||
50 | public function setUp() { |
||
55 | |||
56 | View Code Duplication | public function test_scale_down() { |
|
64 | |||
65 | View Code Duplication | public function test_scale_down_with_max_width() { |
|
76 | |||
77 | View Code Duplication | public function test_scale_down_with_max_filesize() { |
|
86 | |||
87 | View Code Duplication | public function test_scale_down_with_include_source_disabled() { |
|
96 | |||
97 | // TODO: test algorithm |
||
98 | |||
99 | private function createImageObject() { |
||
104 | |||
105 | private function createSourceFile() { |
||
111 | |||
112 | } |
||
113 |
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.