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 |
||
11 | class CheckLinksCommand extends Command |
||
12 | { |
||
13 | /** |
||
14 | * The console command name. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $signature = 'link-checker:run |
||
19 | {--url= : the url to be crawler} |
||
20 | {--profile= : The profiler to be used} |
||
21 | {--reporter= : The reporter to be used} |
||
22 | {--concurrency=10 : The amount of concurrent requests} |
||
23 | '; |
||
24 | /** |
||
25 | * The console command description. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $description = 'Check all links'; |
||
30 | |||
31 | public function handle() |
||
41 | |||
42 | /** |
||
43 | * Returns concurrency. If not found, simply returns a default value like |
||
44 | * 10 (default from spatie/crawler). |
||
45 | * |
||
46 | * @return int |
||
47 | */ |
||
48 | protected function getConcurrency(): int |
||
60 | |||
61 | /** |
||
62 | * Determine the url to be crawled. |
||
63 | * |
||
64 | * @return null|string |
||
65 | * |
||
66 | * @throws \Exception |
||
67 | */ |
||
68 | protected function getUrlToBeCrawled() |
||
84 | |||
85 | /** |
||
86 | * Get the profile. |
||
87 | */ |
||
88 | View Code Duplication | protected function getProfile(): CrawlProfile |
|
100 | |||
101 | /** |
||
102 | * Get the reporter. |
||
103 | */ |
||
104 | View Code Duplication | protected function getReporter(): CrawlObserver |
|
116 | } |
||
117 |
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.