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 |
||
| 7 | class FixedLengthImportForm extends Form |
||
| 8 | { |
||
| 9 | private $_defaultOptions = [ |
||
| 10 | 'line_feed_code' => "\r\n", |
||
| 11 | 'directory' => TMP, |
||
| 12 | 'array_encoding' => 'UTF-8', |
||
| 13 | 'import_encoding' => 'SJIS-win', |
||
| 14 | 'extra_fixed_options' => [] |
||
| 15 | ]; |
||
| 16 | |||
| 17 | /* |
||
| 18 | * loadData 固定長読み込みアクション |
||
| 19 | * |
||
| 20 | * @param string $fileName 固定長テキストファイ |
||
| 21 | * @param array $column_list 各カラム情報(name:カラム名,length:バイト数) |
||
|
|
|||
| 22 | * @param array $options 下記パラメータを必要に応じて設定 |
||
| 23 | * line_feed_code 改行コード(デフォルトは\r\n) |
||
| 24 | * array_encoding 出力するする配列のエンコード(デフォルトはUTF-8 |
||
| 25 | * import_encoding 入力するテキストのエンコード(デフォルトはSJIS-win |
||
| 26 | * extra_fixed_options 出力のための固定長の設定(列によって桁数が異なる場合の設定) |
||
| 27 | */ |
||
| 28 | public function loadData($fileName, $fixed_options, $options = []) |
||
| 39 | |||
| 40 | /* |
||
| 41 | * loadDataBody 固定長内容読み込みアクション |
||
| 42 | * |
||
| 43 | * @param string $data 固定長テキストデータ |
||
| 44 | * @param array $column_list 各カラム情報(name:カラム名,length:バイト数) |
||
| 45 | * @param array $options 下記パラメータを必要に応じて設定 |
||
| 46 | * line_feed_code 改行コード(デフォルトは\r\n) |
||
| 47 | * array_encoding 出力するする配列のエンコード(デフォルトはUTF-8 |
||
| 48 | * import_encoding 入力するテキストのエンコード(デフォルトはSJIS-win |
||
| 49 | * extra_fixed_options 出力のための固定長の設定(列によって桁数が異なる場合の設定) |
||
| 50 | */ |
||
| 51 | public function loadDataBody($data, $fixed_options, $options = []) |
||
| 84 | } |
||
| 85 |
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.