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 |
||
16 | class ChronosJobEntity implements JobEntityInterface |
||
17 | { |
||
18 | public $name = ''; |
||
19 | |||
20 | public $command = ''; |
||
21 | |||
22 | public $description = ''; |
||
23 | |||
24 | public $owner = ''; |
||
25 | |||
26 | public $ownerName = ''; |
||
27 | |||
28 | public $schedule = ''; // todo: move to separate entity |
||
29 | |||
30 | public $scheduleTimeZone = ''; |
||
31 | |||
32 | public $parents = []; // todo: move to separate entity |
||
33 | |||
34 | public $epsilon = ''; |
||
35 | |||
36 | public $executor = ''; |
||
37 | |||
38 | public $executorFlags = ''; |
||
39 | |||
40 | public $shell = true; |
||
41 | |||
42 | public $retries = 0; |
||
43 | |||
44 | public $async = false; |
||
45 | |||
46 | public $successCount = 0; |
||
47 | |||
48 | public $errorCount = 0; |
||
49 | |||
50 | public $errorsSinceLastSuccess = 0; |
||
51 | |||
52 | public $lastSuccess = ''; |
||
53 | |||
54 | public $lastError = ''; |
||
55 | |||
56 | public $cpus = 0.1; |
||
57 | |||
58 | public $disk = 24; |
||
59 | |||
60 | public $mem = 32; |
||
61 | |||
62 | public $disabled = false; |
||
63 | |||
64 | public $softError = false; |
||
65 | |||
66 | public $dataProcessingJobType = false; |
||
67 | |||
68 | public $uris = []; |
||
69 | |||
70 | public $environmentVariables = []; |
||
71 | |||
72 | public $arguments = []; |
||
73 | |||
74 | public $highPriority = false; |
||
75 | |||
76 | public $runAsUser = 'root'; |
||
77 | |||
78 | public $constraints = []; |
||
79 | |||
80 | /** @var ContainerEntity */ |
||
81 | public $container = null; |
||
82 | |||
83 | |||
84 | /** |
||
85 | * @param array|object $mJobData |
||
86 | * @throws \InvalidArgumentException |
||
87 | */ |
||
88 | 115 | public function __construct($mJobData = []) |
|
112 | |||
113 | /** |
||
114 | * return entity as one-dimensional array |
||
115 | * |
||
116 | * @return mixed[] |
||
117 | */ |
||
118 | 8 | View Code Duplication | public function getSimpleArrayCopy() |
129 | |||
130 | /** |
||
131 | * @return bool |
||
132 | */ |
||
133 | 18 | public function isSchedulingJob() |
|
137 | |||
138 | /** |
||
139 | * @return bool |
||
140 | */ |
||
141 | 7 | public function isDependencyJob() |
|
145 | |||
146 | /** |
||
147 | * @return array |
||
148 | */ |
||
149 | 11 | public function jsonSerialize() |
|
175 | |||
176 | /** |
||
177 | * @return \ArrayIterator |
||
178 | */ |
||
179 | 9 | public function getIterator() |
|
183 | |||
184 | /** |
||
185 | * @return string |
||
186 | */ |
||
187 | 5 | public function getEntityType() |
|
191 | |||
192 | /** |
||
193 | * @return string |
||
194 | */ |
||
195 | 40 | public function getKey() |
|
199 | } |
||
200 |
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.