Conditions | 11 |
Paths | 40 |
Total Lines | 67 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
67 | public function readData($option): array |
||
68 | { |
||
69 | //$this->logger->error('dataset path: ' . $datasetMetadata['link']); |
||
70 | |||
71 | $data = array(); |
||
72 | $header = array(); |
||
73 | $headerrow = 0; |
||
74 | $selectedColumns = array(); |
||
75 | |||
76 | $ch = curl_init(); |
||
77 | if ($ch !== false) { |
||
78 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); |
||
79 | curl_setopt($ch, CURLOPT_HEADER, false); |
||
80 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
||
81 | curl_setopt($ch, CURLOPT_URL, $option['link']); |
||
82 | curl_setopt($ch, CURLOPT_REFERER, $option['link']); |
||
83 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
||
84 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); |
||
85 | $curlResult = curl_exec($ch); |
||
86 | curl_close($ch); |
||
87 | } else { |
||
88 | $curlResult = ''; |
||
89 | } |
||
90 | |||
91 | $rows = str_getcsv($curlResult, "\n"); |
||
|
|||
92 | |||
93 | // remove x number of rows from the beginning |
||
94 | if (isset($option['offset']) and is_numeric($option['offset'])) { |
||
95 | $rows = array_slice($rows, $option['offset']); |
||
96 | } |
||
97 | |||
98 | // ensure that all values are integers |
||
99 | if (isset($option['columns'])) { |
||
100 | $new = array(); |
||
101 | $selectedColumns = str_getcsv($option['columns'], ','); |
||
102 | foreach ($selectedColumns as $value) { |
||
103 | if (is_numeric($value)) { |
||
104 | array_push($new, $value); |
||
105 | } |
||
106 | } |
||
107 | $selectedColumns = $new; |
||
108 | } |
||
109 | |||
110 | $delimiter = $this->detectDelimiter($rows[0]); |
||
111 | |||
112 | foreach ($rows as &$row) { |
||
113 | $row = str_getcsv($row, $delimiter); |
||
114 | $rowMinimized = array(); |
||
115 | |||
116 | if (count($selectedColumns) !== 0) { |
||
117 | foreach ($selectedColumns as $selectedColumn) { |
||
118 | array_push($rowMinimized, $row[$selectedColumn - 1]); |
||
119 | } |
||
120 | } else { |
||
121 | $rowMinimized = $row; |
||
122 | } |
||
123 | |||
124 | if ($headerrow === 0) { |
||
125 | $header = $rowMinimized; |
||
126 | $headerrow = 1; |
||
127 | } else { |
||
128 | array_push($data, $rowMinimized); |
||
129 | } |
||
130 | } |
||
131 | return [ |
||
132 | 'header' => $header, |
||
133 | 'data' => $data |
||
134 | ]; |
||
152 | } |