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 |
||
10 | View Code Duplication | class InstallManagerController extends Controller |
|
|
|||
11 | { |
||
12 | /* |
||
13 | * When including this trait make sure you inject RepositoryContract as $repository |
||
14 | * and CustomersRepository as $customers to the constructor |
||
15 | */ |
||
16 | use VerifiesPurchase; |
||
17 | |||
18 | /** |
||
19 | * Update Repository. |
||
20 | * |
||
21 | * @var mixed |
||
22 | **/ |
||
23 | public $repository; |
||
24 | |||
25 | /** |
||
26 | * Customers Repository. |
||
27 | * |
||
28 | * @var mixed |
||
29 | **/ |
||
30 | public $customers; |
||
31 | |||
32 | /** |
||
33 | * Create a new instance of the UpdatesManagerController::class. |
||
34 | **/ |
||
35 | public function __construct(RepositoryContract $repository, CustomersRepository $customers) |
||
40 | |||
41 | /** |
||
42 | * Get the installer zip file for the version specified |
||
43 | * NOTE: The purchase key must be passed in the request for verification. |
||
44 | * |
||
45 | * @return mixed Illuminate\Http\Response |
||
46 | * |
||
47 | * @param $version Version to fetch |
||
48 | **/ |
||
49 | public function getInstaller($version) |
||
60 | } |
||
61 |
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.