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 |
||
| 9 | class Addon |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
| 13 | * @param string $path |
||
| 14 | * |
||
| 15 | * @return static |
||
| 16 | */ |
||
| 17 | 8 | public static function create($app, $path) |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @param string $path |
||
| 30 | * @param string $name |
||
| 31 | * |
||
| 32 | * @return array |
||
| 33 | */ |
||
| 34 | 8 | protected static function loadAddonConfig($path, $name) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * @var \Illuminate\Contracts\Foundation\Application |
||
| 52 | */ |
||
| 53 | protected $app; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var string |
||
| 57 | */ |
||
| 58 | protected $name; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var string |
||
| 62 | */ |
||
| 63 | protected $path; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var \Illuminate\Contracts\Config\Repository |
||
| 67 | */ |
||
| 68 | protected $config; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
| 72 | * @param string $name |
||
| 73 | * @param string $path |
||
| 74 | * @param array $config |
||
| 75 | */ |
||
| 76 | 16 | public function __construct($app, $name, $path, array $config) |
|
| 84 | |||
| 85 | /** |
||
| 86 | * get name. |
||
| 87 | * |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | 11 | public function name() |
|
| 94 | |||
| 95 | /** |
||
| 96 | * get fullpath. |
||
| 97 | * |
||
| 98 | * @param string $path |
||
| 99 | * |
||
| 100 | * @return string |
||
| 101 | */ |
||
| 102 | 7 | public function path($path = null) |
|
| 110 | |||
| 111 | /** |
||
| 112 | * get relative path. |
||
| 113 | * |
||
| 114 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
| 115 | * |
||
| 116 | * @return string |
||
| 117 | */ |
||
| 118 | 8 | public function relativePath(Application $app) |
|
| 122 | |||
| 123 | /** |
||
| 124 | * get version. |
||
| 125 | * |
||
| 126 | * @return int |
||
| 127 | */ |
||
| 128 | 2 | public function version() |
|
| 132 | |||
| 133 | /** |
||
| 134 | * get PHP namespace. |
||
| 135 | * |
||
| 136 | * @return string |
||
| 137 | */ |
||
| 138 | 8 | public function phpNamespace() |
|
| 142 | |||
| 143 | /** |
||
| 144 | * get config value. |
||
| 145 | * |
||
| 146 | * @param string $key |
||
| 147 | * @param mixed $default |
||
| 148 | * |
||
| 149 | * @return mixed |
||
| 150 | */ |
||
| 151 | 11 | public function config($key, $default = null) |
|
| 155 | |||
| 156 | /** |
||
| 157 | * Get a lang resource name |
||
| 158 | * |
||
| 159 | * @param string $resource |
||
| 160 | * |
||
| 161 | * @return string |
||
| 162 | */ |
||
| 163 | 1 | public function transName($resource) |
|
| 167 | |||
| 168 | /** |
||
| 169 | * Translate the given message. |
||
| 170 | * |
||
| 171 | * @param string $id |
||
|
|
|||
| 172 | * @param array $parameters |
||
| 173 | * @param string $domain |
||
| 174 | * @param string $locale |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | 1 | View Code Duplication | public function trans() |
| 184 | |||
| 185 | /** |
||
| 186 | * Translates the given message based on a count. |
||
| 187 | * |
||
| 188 | * @param string $id |
||
| 189 | * @param int $number |
||
| 190 | * @param array $parameters |
||
| 191 | * @param string $domain |
||
| 192 | * @param string $locale |
||
| 193 | * @return string |
||
| 194 | */ |
||
| 195 | 1 | View Code Duplication | public function transChoice() |
| 202 | |||
| 203 | /** |
||
| 204 | * Get a view resource name |
||
| 205 | * |
||
| 206 | * @param string $resource |
||
| 207 | * |
||
| 208 | * @return string |
||
| 209 | */ |
||
| 210 | public function viewName($resource) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @param string $view |
||
| 217 | * @param array $data |
||
| 218 | * @param array $mergeData |
||
| 219 | * |
||
| 220 | * @return \Illuminate\View\View |
||
| 221 | */ |
||
| 222 | public function view($view, $data = [], $mergeData = []) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Get a spec resource name |
||
| 229 | * |
||
| 230 | * @param string $resource |
||
| 231 | * |
||
| 232 | * @return string |
||
| 233 | */ |
||
| 234 | public function specName($resource) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Get spec. |
||
| 241 | * |
||
| 242 | * @param string $path |
||
| 243 | * |
||
| 244 | * @return \Jumilla\Addomnipot\Laravel\Specs\InputSpec |
||
| 245 | */ |
||
| 246 | public function spec($path) |
||
| 250 | } |
||
| 251 |
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.