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 namespace Indatus\Dispatcher\Scheduling; |
||
14 | abstract class Schedulable |
||
15 | { |
||
16 | /** @var array $arguments */ |
||
17 | protected $arguments = []; |
||
18 | |||
19 | /** @var array $options */ |
||
20 | protected $options = []; |
||
21 | |||
22 | /** @var bool Instantiate a new instance when using args() or opts() */ |
||
23 | protected $instantiateNew = true; |
||
24 | |||
25 | /** |
||
26 | * Define arguments for this schedule when it runs. |
||
27 | * |
||
28 | * @param array $arguments |
||
29 | * |
||
30 | * @return \Indatus\Dispatcher\Scheduling\Schedulable |
||
31 | */ |
||
32 | 3 | View Code Duplication | public function args(array $arguments) |
49 | |||
50 | /** |
||
51 | * Get the arguments for this schedule. |
||
52 | * |
||
53 | * @return array |
||
54 | */ |
||
55 | 3 | public function getArguments() |
|
59 | |||
60 | /** |
||
61 | * Set the schedule's arguments |
||
62 | * |
||
63 | * This method is only to be used internally by Dispatcher. |
||
64 | * |
||
65 | * @param array $arguments |
||
66 | */ |
||
67 | 3 | public function setArguments($arguments) |
|
71 | |||
72 | /** |
||
73 | * Define options for this schedule when it runs. |
||
74 | * |
||
75 | * @param array $options |
||
76 | * |
||
77 | * @return \Indatus\Dispatcher\Scheduling\Schedulable |
||
78 | */ |
||
79 | 2 | View Code Duplication | public function opts(array $options) |
96 | |||
97 | /** |
||
98 | * Get the options for this schedule. |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | 2 | public function getOptions() |
|
106 | |||
107 | /** |
||
108 | * Set the schedule's options |
||
109 | * |
||
110 | * This method is only to be used internally by Dispatcher. |
||
111 | * |
||
112 | * @param array $options |
||
113 | */ |
||
114 | 2 | public function setOptions($options) |
|
119 | |||
120 | /** |
||
121 | * Propagate scheduled:run environment |
||
122 | * to scheduled commands, only if 'env' option was not specified |
||
123 | */ |
||
124 | 2 | private function setEnvironmentOption() |
|
133 | } |
||
134 |
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.