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 | class LiveJobsGridSource extends DocumentGridSource |
||
11 | { |
||
12 | protected $jobManager; |
||
13 | protected $running = false; |
||
14 | |||
15 | 1 | public function getId() |
|
16 | { |
||
17 | 1 | return 'dtc_queue.grid_source.jobs_'.($this->isRunning() ? 'running' : 'waiting').'.odm'; |
|
18 | } |
||
19 | |||
20 | 7 | public function setRunning($flag) |
|
24 | |||
25 | 2 | public function isRunning() |
|
29 | |||
30 | 1 | protected function getRunningQueryBuilder() |
|
42 | |||
43 | 7 | public function __construct(JobManager $jobManager) |
|
51 | |||
52 | 2 | public function getColumns() |
|
53 | { |
||
54 | 2 | if ($columns = parent::getColumns()) { |
|
55 | 1 | return $columns; |
|
56 | } |
||
57 | 2 | $this->autoDiscoverColumns(); |
|
58 | |||
59 | 2 | return parent::getColumns(); |
|
60 | } |
||
61 | |||
62 | 2 | View Code Duplication | public function autoDiscoverColumns() |
73 | |||
74 | 2 | public function getDefaultSort() |
|
78 | |||
79 | 1 | View Code Duplication | protected function getQueryBuilder() |
90 | } |
||
91 |
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.