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 |
||
| 8 | class EnvironmentOverview extends Dispatcher { |
||
| 9 | |||
| 10 | const ACTION_OVERVIEW = 'overview'; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var array |
||
| 14 | */ |
||
| 15 | private static $action_types = [ |
||
| 16 | self::ACTION_OVERVIEW |
||
| 17 | ]; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * The "deployment" action here should only go to index, it gets used by |
||
| 21 | * the frontend routing. |
||
| 22 | */ |
||
| 23 | private static $allowed_actions = [ |
||
| 24 | 'deployment' |
||
| 25 | ]; |
||
| 26 | |||
| 27 | View Code Duplication | public function init() { |
|
| 36 | |||
| 37 | /** |
||
| 38 | * |
||
| 39 | * @param \SS_HTTPRequest $request |
||
| 40 | * |
||
| 41 | * @return \HTMLText|\SS_HTTPResponse |
||
| 42 | */ |
||
| 43 | public function index(\SS_HTTPRequest $request) { |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return string |
||
| 57 | */ |
||
| 58 | public function Link() { |
||
| 61 | |||
| 62 | /** |
||
| 63 | * The model includes the CSRF tokens and the various API |
||
| 64 | * endpoints that the front end might be interested in. |
||
| 65 | * |
||
| 66 | * @param string $name |
||
| 67 | * |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | public function getModel($name = '') { |
||
| 97 | |||
| 98 | } |
||
| 99 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.