Conditions | 11 |
Paths | 40 |
Total Lines | 58 |
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 |
||
74 | public function readData($option): array |
||
75 | { |
||
76 | $data = array(); |
||
77 | $header = array(); |
||
78 | $headerrow = $errorMessage = 0; |
||
79 | $selectedColumns = array(); |
||
80 | |||
81 | if (isset($option['path'])) { |
||
82 | $file = $this->rootFolder->getUserFolder($this->userId)->get($option['path']); |
||
83 | } else { |
||
84 | //$this->logger->debug('FileService 53 file content:' . $option['user_id'] . $option['link']); |
||
85 | $file = $this->rootFolder->getUserFolder($option['user_id'])->get($option['link']); |
||
86 | } |
||
87 | |||
88 | $rows = str_getcsv($file->getContent(), "\n"); |
||
|
|||
89 | |||
90 | // remove x number of rows from the beginning |
||
91 | if (isset($option['offset']) and is_numeric($option['offset'])) { |
||
92 | $rows = array_slice($rows, $option['offset']); |
||
93 | } |
||
94 | |||
95 | // ensure that all values are integers |
||
96 | if (isset($option['columns'])) { |
||
97 | $new = array(); |
||
98 | $selectedColumns = str_getcsv($option['columns'], ','); |
||
99 | foreach ($selectedColumns as $value) { |
||
100 | if (is_numeric($value)) { |
||
101 | array_push($new, $value); |
||
102 | } |
||
103 | } |
||
104 | $selectedColumns = $new; |
||
105 | } |
||
106 | |||
107 | $delimiter = $this->detectDelimiter($rows[0]); |
||
108 | |||
109 | foreach ($rows as &$row) { |
||
110 | $row = str_getcsv($row, $delimiter); |
||
111 | $rowMinimized = array(); |
||
112 | |||
113 | if (count($selectedColumns) !== 0) { |
||
114 | foreach ($selectedColumns as $selectedColumn) { |
||
115 | array_push($rowMinimized, $row[$selectedColumn - 1]); |
||
116 | } |
||
117 | } else { |
||
118 | $rowMinimized = $row; |
||
119 | } |
||
120 | |||
121 | if ($headerrow === 0) { |
||
122 | $header = $rowMinimized; |
||
123 | $headerrow = 1; |
||
124 | } else { |
||
125 | array_push($data, $rowMinimized); |
||
126 | } |
||
127 | } |
||
128 | return [ |
||
129 | 'header' => $header, |
||
130 | 'data' => $data, |
||
131 | 'error' => $errorMessage, |
||
132 | ]; |
||
150 | } |