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 Anomaly\Streams\Platform\Entry; |
||
14 | class EntryTranslationsModel extends EloquentModel |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * This model uses timestamps. |
||
19 | * |
||
20 | * @var bool |
||
21 | */ |
||
22 | public $timestamps = true; |
||
23 | |||
24 | /** |
||
25 | * Cache minutes. |
||
26 | * |
||
27 | * @var int |
||
28 | */ |
||
29 | //protected $cacheMinutes = 99999; |
||
|
|||
30 | |||
31 | /** |
||
32 | * Boot the model. |
||
33 | */ |
||
34 | protected static function boot() |
||
40 | |||
41 | /** |
||
42 | * Return the last modified datetime. |
||
43 | * |
||
44 | * @return Carbon |
||
45 | */ |
||
46 | public function lastModified() |
||
50 | |||
51 | /** |
||
52 | * Get the locale. |
||
53 | * |
||
54 | * @return string |
||
55 | */ |
||
56 | public function getLocale() |
||
60 | |||
61 | /** |
||
62 | * Get an attribute. |
||
63 | * |
||
64 | * @param string $key |
||
65 | * @return mixed |
||
66 | */ |
||
67 | public function getAttribute($key) |
||
94 | |||
95 | /** |
||
96 | * Get the parent. |
||
97 | * |
||
98 | * @return EntryModel |
||
99 | */ |
||
100 | public function getParent() |
||
104 | |||
105 | /** |
||
106 | * Set the attribute. |
||
107 | * |
||
108 | * @param string $key |
||
109 | * @param mixed $value |
||
110 | */ |
||
111 | View Code Duplication | public function setAttribute($key, $value) |
|
136 | |||
137 | /** |
||
138 | * Fire field type events. |
||
139 | * |
||
140 | * @param $trigger |
||
141 | * @param array $payload |
||
142 | */ |
||
143 | public function fireFieldTypeEvents($trigger, $payload = []) |
||
163 | |||
164 | /** |
||
165 | * Truncate the translation's table. |
||
166 | * |
||
167 | * @return mixed |
||
168 | */ |
||
169 | public function truncate() |
||
173 | |||
174 | /** |
||
175 | * Let the parent handle calls if they don't exist here. |
||
176 | * |
||
177 | * @param string $name |
||
178 | * @param array $arguments |
||
179 | * @return mixed |
||
180 | */ |
||
181 | public function __call($name, $arguments) |
||
185 | |||
186 | /** |
||
187 | * Get the attribute from the parent |
||
188 | * if it does not exist here. |
||
189 | * |
||
190 | * @param string $key |
||
191 | * @return mixed |
||
192 | */ |
||
193 | public function __get($key) |
||
203 | } |
||
204 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.