Conditions | 8 |
Paths | 64 |
Total Lines | 54 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
16 | public function import($fileName, $columnList = [], $options = []) |
||
17 | { |
||
18 | $options = $this->getOptions($options); |
||
19 | extract($options); |
||
20 | |||
21 | //保存をするのでモデルを読み込み |
||
22 | try { |
||
23 | $data = array(); |
||
24 | $csvData = array(); |
||
25 | $file = fopen($fileName,"r"); |
||
26 | while($data = $this->fgetcsv_reg($file, 65536, $delimiter)) {//CSVファイルを","区切りで配列に |
||
27 | mb_convert_variables($arrayEncoding, $importEncoding, $data); |
||
28 | $csvData[] = $data; |
||
29 | } |
||
30 | |||
31 | $i = 0; |
||
32 | foreach ($csvData as $line) { |
||
33 | $thisData = array(); |
||
34 | if (empty($columnList)) { |
||
35 | $thisColumnList = array(); |
||
36 | $lineCount = 0; |
||
37 | foreach ($line as $line_v) { |
||
38 | $thisColumnList[] = $lineCount; |
||
39 | $lineCount++; |
||
40 | } |
||
41 | } else { |
||
42 | $thisColumnList = $columnList; |
||
43 | } |
||
44 | foreach ($thisColumnList as $k => $v) { |
||
45 | if (isset($line[$k])) { |
||
46 | //先頭と末尾の"を削除 |
||
47 | $b = $line[$k]; |
||
48 | //カラムの数だけセット |
||
49 | $thisData = array_merge( |
||
50 | $thisData, |
||
51 | array($v => $b) |
||
52 | ); |
||
53 | } else { |
||
54 | $thisData = array_merge( |
||
55 | $thisData, |
||
56 | array($v => '') |
||
57 | ); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | $data[$i] = $thisData; |
||
62 | $i++; |
||
63 | } |
||
64 | } catch (Exception $e) { |
||
65 | return false; |
||
66 | } |
||
67 | |||
68 | return $data; |
||
69 | } |
||
70 | |||
112 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.