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 |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Erdiko Helper |
||
| 17 | * |
||
| 18 | * Some global helpers |
||
| 19 | * |
||
| 20 | * @package erdiko/core |
||
| 21 | * @copyright 2012-2017 Arroyo Labs, Inc. http://www.arroyolabs.com |
||
| 22 | * @author John Arroyo <[email protected]> |
||
| 23 | */ |
||
| 24 | namespace erdiko; |
||
| 25 | |||
| 26 | |||
| 27 | class Helper |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Log Object |
||
| 31 | */ |
||
| 32 | protected static $_logObject=null; // @todo get rid of this |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Serve your site |
||
| 36 | * Loads routes based off of context and serves up the current request |
||
| 37 | * |
||
| 38 | * @param string $context optional context defaults to getenv('ERDIKO_CONTEXT') |
||
| 39 | */ |
||
| 40 | public static function serve($context = null) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Load a view from the current theme with the given data |
||
| 51 | * |
||
| 52 | * @param string $viewName |
||
| 53 | * @param array $data |
||
| 54 | */ |
||
| 55 | public static function getView($viewName, $data = null, $templateRootFolder = null) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Read JSON config file and return array |
||
| 67 | * |
||
| 68 | * @param string $file |
||
|
|
|||
| 69 | * @return array $config |
||
| 70 | */ |
||
| 71 | View Code Duplication | public static function getConfigFile($filename) |
|
| 88 | |||
| 89 | /** |
||
| 90 | * Get configuration |
||
| 91 | */ |
||
| 92 | View Code Duplication | public static function getConfig($name = 'application', $context = null) |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Get the compiled application routes from the config files |
||
| 103 | * |
||
| 104 | * @todo cache the loaded/compiled routes |
||
| 105 | */ |
||
| 106 | View Code Duplication | public static function getRoutes($context = null) |
|
| 115 | |||
| 116 | /** |
||
| 117 | * Send email |
||
| 118 | * @todo add ways to swap out ways of sending |
||
| 119 | */ |
||
| 120 | public static function sendEmail($toEmail, $subject, $body, $fromEmail) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * log message to log file |
||
| 131 | * If you enter null for level it will default to 'debug' |
||
| 132 | * |
||
| 133 | * @usage \Erdiko::log('debug',"Message here...", array()) |
||
| 134 | * |
||
| 135 | * @param string $level |
||
| 136 | * @param string $message |
||
| 137 | * @param array $context |
||
| 138 | * @return bool $success |
||
| 139 | * @todo refactor how logging is used, eventually remove from helper |
||
| 140 | */ |
||
| 141 | public static function log($level, $message, array $context = array()) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * log debug message to log file |
||
| 161 | * |
||
| 162 | * @param string $message |
||
| 163 | * @param array $context |
||
| 164 | * @return bool $success |
||
| 165 | * @todo refactor how logging is used, eventually remove from helper |
||
| 166 | */ |
||
| 167 | public static function debug($message, array $context = array()) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * log error message to log file |
||
| 174 | * |
||
| 175 | * @param string $message |
||
| 176 | * @param array $context |
||
| 177 | * @return bool $success |
||
| 178 | * @todo refactor how logging is used, eventually remove from helper |
||
| 179 | */ |
||
| 180 | public static function error($message, array $context = array()) |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Get the configured cache instance using name |
||
| 187 | * |
||
| 188 | * @return cache $cache returns the instance of the cache type |
||
| 189 | */ |
||
| 190 | public static function getCache($cacheType = "default") |
||
| 191 | { |
||
| 204 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.