Conditions | 8 |
Paths | 64 |
Total Lines | 51 |
Code Lines | 34 |
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 |
||
27 | public function loadDataCsv($fileName, $column_list = array(), $delimiter = ",", $array_encoding = 'utf8',$import_encoding = 'sjis-win') |
||
28 | { |
||
29 | //保存をするのでモデルを読み込み |
||
30 | try { |
||
31 | $data = array(); |
||
32 | $csvData = array(); |
||
33 | $file = fopen($fileName,"r"); |
||
34 | while($data = $this->fgetcsv_reg($file,65536,$delimiter)){//CSVファイルを","区切りで配列に |
||
35 | mb_convert_variables($array_encoding,$import_encoding,$data); |
||
36 | $csvData[] = $data; |
||
37 | } |
||
38 | |||
39 | $i = 0; |
||
40 | foreach ($csvData as $line) { |
||
41 | $this_data = array(); |
||
42 | if (empty($column_list)) { |
||
43 | $this_column_list = array(); |
||
44 | $line_count = 0; |
||
45 | foreach ($line as $line_v) { |
||
46 | $this_column_list[] = $line_count; |
||
47 | $line_count++; |
||
48 | } |
||
49 | } else { |
||
50 | $this_column_list = $column_list; |
||
51 | } |
||
52 | foreach ($this_column_list as $k => $v) { |
||
53 | if (isset($line[$k])) { |
||
54 | //先頭と末尾の"を削除 |
||
55 | $b = $line[$k]; |
||
56 | //カラムの数だけセット |
||
57 | $this_data = Hash::merge( |
||
58 | $this_data, |
||
59 | array($v => $b) |
||
60 | ); |
||
61 | } else { |
||
62 | $this_data = Hash::merge( |
||
63 | $this_data, |
||
64 | array($v => '') |
||
65 | ); |
||
66 | } |
||
67 | } |
||
68 | |||
69 | $data[$i] = $this_data; |
||
70 | $i++; |
||
71 | } |
||
72 | } catch (\Exception $e) { |
||
73 | return false; |
||
74 | } |
||
75 | |||
76 | return $data; |
||
77 | } |
||
78 | |||
120 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.