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 |
||
21 | class MarathonAppEntity implements JobEntityInterface |
||
22 | { |
||
23 | public $id = ''; |
||
24 | |||
25 | public $cmd = ''; |
||
26 | |||
27 | public $cpus = 0; |
||
28 | |||
29 | public $mem = 0; |
||
30 | |||
31 | public $args = []; |
||
32 | |||
33 | /** |
||
34 | * @var PortDefinition[] |
||
35 | */ |
||
36 | public $portDefinitions =[]; |
||
37 | |||
38 | public $requirePorts = false; |
||
39 | |||
40 | public $instances = 0; |
||
41 | |||
42 | public $executor = ''; |
||
43 | |||
44 | /** |
||
45 | * @var Container |
||
46 | */ |
||
47 | public $container = null; |
||
48 | |||
49 | public $env = null; |
||
50 | |||
51 | /** |
||
52 | * @var array |
||
53 | */ |
||
54 | public $constraints = []; |
||
55 | |||
56 | |||
57 | public $acceptedResourceRoles = []; |
||
58 | |||
59 | public $labels = null; |
||
60 | |||
61 | public $uris = []; |
||
62 | |||
63 | public $dependencies = []; |
||
64 | |||
65 | /** |
||
66 | * @var HealthCheck[] |
||
67 | */ |
||
68 | public $healthChecks = []; |
||
69 | |||
70 | public $backoffSeconds = 1; |
||
71 | |||
72 | public $backoffFactor = 1.15; |
||
73 | |||
74 | public $maxLaunchDelaySeconds = 3600; |
||
75 | |||
76 | public $taskKillGracePeriodSeconds = 0; |
||
77 | |||
78 | /** |
||
79 | * @var UpgradeStrategy |
||
80 | */ |
||
81 | public $upgradeStrategy = null; |
||
82 | |||
83 | |||
84 | /** |
||
85 | * @var IpAddress |
||
86 | */ |
||
87 | public $ipAddress = null; |
||
88 | |||
89 | 45 | public function __construct($mData = null) |
|
149 | |||
150 | /** |
||
151 | * @inheritdoc |
||
152 | * @return array |
||
153 | */ |
||
154 | 4 | public function jsonSerialize() |
|
159 | |||
160 | /** |
||
161 | * @inheritdoc |
||
162 | * @return \ArrayIterator |
||
163 | */ |
||
164 | 2 | public function getIterator() |
|
168 | |||
169 | /** |
||
170 | * @inheritdoc |
||
171 | * @return array |
||
172 | */ |
||
173 | 2 | View Code Duplication | public function getSimpleArrayCopy() |
184 | |||
185 | /** |
||
186 | * @inheritdoc |
||
187 | * @return bool |
||
188 | */ |
||
189 | public function isSchedulingJob() |
||
193 | |||
194 | /** |
||
195 | * @inheritdoc |
||
196 | * @return bool |
||
197 | */ |
||
198 | 5 | public function isDependencyJob() |
|
202 | |||
203 | /** |
||
204 | * @return string |
||
205 | */ |
||
206 | 5 | public function getEntityType() |
|
210 | |||
211 | /** |
||
212 | * @return string |
||
213 | */ |
||
214 | 23 | public function getKey() |
|
218 | } |
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.