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 |
||
| 3 | class SupportedAddonsApiController extends Controller |
||
| 4 | { |
||
| 5 | private static $allowed_actions = [ |
||
|
|
|||
| 6 | 'index', |
||
| 7 | ]; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Set the default cache lifetime in seconds. Only used outside of "dev" environments. |
||
| 11 | * |
||
| 12 | * @config |
||
| 13 | * @var int |
||
| 14 | */ |
||
| 15 | private static $cache_age = 86400; // 24 hours |
||
| 16 | |||
| 17 | public function index() |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Given a result payload, format as a JSON response and return |
||
| 28 | * |
||
| 29 | * @param array $data |
||
| 30 | * @return SS_HTTPResponse |
||
| 31 | */ |
||
| 32 | View Code Duplication | protected function formatResponse(array $data) |
|
| 48 | } |
||
| 49 |