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 |
||
20 | class LaravelTestCase extends \Illuminate\Foundation\Testing\TestCase |
||
21 | { |
||
22 | /** |
||
23 | * Setup DB before each test. |
||
24 | */ |
||
25 | public function setUp() |
||
36 | |||
37 | /** |
||
38 | * run package database migrations. |
||
39 | */ |
||
40 | View Code Duplication | public function migrate() |
|
52 | |||
53 | /** |
||
54 | * |
||
55 | */ |
||
56 | public function tearDown() |
||
61 | |||
62 | /** |
||
63 | * run package database migrations. |
||
64 | */ |
||
65 | View Code Duplication | public function destroy() |
|
77 | |||
78 | /** |
||
79 | * Boots the application. |
||
80 | * |
||
81 | * @return \Illuminate\Foundation\Application |
||
82 | */ |
||
83 | public function createApplication() |
||
91 | } |
||
92 |
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.