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 |
||
6 | class FixedLengthImport extends AppImport |
||
7 | { |
||
8 | |||
9 | /* |
||
10 | * loadData 固定長読み込みアクション |
||
11 | * |
||
12 | * @param string $fileName 固定長テキストファイ |
||
13 | * @param array $columnList 各カラム情報(name:カラム名,length:バイト数) |
||
14 | * @param array $options 下記パラメータを必要に応じて設定 |
||
15 | * line_feed_code 改行コード(デフォルトは\r\n) |
||
16 | * array_encoding 出力するする配列のエンコード(デフォルトはUTF-8 |
||
17 | * import_encoding 入力するテキストのエンコード(デフォルトはSJIS-win |
||
18 | * extra_fixed_options 出力のための固定長の設定(列によって桁数が異なる場合の設定) |
||
19 | */ |
||
20 | public function import($fileName, $columnList, $options = []) |
||
31 | |||
32 | /* |
||
33 | * importBody 固定長内容読み込みアクション |
||
34 | * |
||
35 | * @param string $data 固定長テキストデータ |
||
36 | * @param array $baseColumnList 各カラム情報(name:カラム名,length:バイト数) |
||
37 | * @param array $options 下記パラメータを必要に応じて設定 |
||
38 | * line_feed_code 改行コード(デフォルトは\r\n) |
||
39 | * array_encoding 出力するする配列のエンコード(デフォルトはUTF-8 |
||
40 | * import_encoding 入力するテキストのエンコード(デフォルトはSJIS-win |
||
41 | * extra_fixed_options 出力のための固定長の設定(列によって桁数が異なる場合の設定) |
||
42 | */ |
||
43 | public function importBody($data, $baseColumnList, $options = []) |
||
80 | } |
||
81 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.