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 |
||
8 | class ExactValueTokenTest extends TestCase { |
||
9 | /** |
||
10 | * @test |
||
11 | * @see https://github.com/phpspec/prophecy/issues/268 |
||
12 | * @see https://stackoverflow.com/a/19097159/2424814 |
||
13 | */ |
||
14 | View Code Duplication | public function does_not_trigger_nesting_error() { |
|
21 | |||
22 | /** |
||
23 | * @test |
||
24 | */ |
||
25 | View Code Duplication | public function scores_10_for_objects_with_same_fields() { |
|
32 | |||
33 | /** |
||
34 | * @test |
||
35 | */ |
||
36 | public function scores_10_for_matching_callables() { |
||
42 | |||
43 | /** |
||
44 | * @test |
||
45 | */ |
||
46 | public function scores_false_for_object_and_string() { |
||
52 | |||
53 | /** |
||
54 | * @test |
||
55 | */ |
||
56 | public function scores_false_for_object_and_int() { |
||
62 | |||
63 | /** |
||
64 | * @test |
||
65 | */ |
||
66 | public function scores_false_for_object_and_stdclass() { |
||
72 | |||
73 | /** |
||
74 | * @test |
||
75 | */ |
||
76 | public function scores_false_for_object_and_null() { |
||
82 | } |
||
83 | |||
106 |
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.