Conditions | 10 |
Paths | 32 |
Total Lines | 47 |
Code Lines | 26 |
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 |
||
76 | public function readData($option): array |
||
77 | { |
||
78 | $error = 0; |
||
79 | $file = $this->rootFolder->getUserFolder($option['user_id'])->get($option['link']); |
||
80 | $rows = str_getcsv($file->getContent(), "\n"); |
||
81 | |||
82 | // remove x number of rows from the beginning |
||
83 | if (isset($option['offset']) and is_numeric($option['offset'])) { |
||
84 | $rows = array_slice($rows, $option['offset']); |
||
85 | } |
||
86 | |||
87 | $selectedColumns = array(); |
||
88 | if (isset($option['columns']) && strlen($option['columns']) > 0) { |
||
89 | $selectedColumns = str_getcsv($option['columns'], ','); |
||
90 | } |
||
91 | |||
92 | // get the delimiter by reading the first row |
||
93 | $delimiter = $this->detectDelimiter($rows[0]); |
||
94 | |||
95 | // the first row will define the column headers, even if it is not a real header |
||
96 | // trim removes any leading or ending spaces |
||
97 | $header = array_map('trim', str_getcsv($rows[0], $delimiter)); |
||
98 | |||
99 | // if the data has a real header, remove the first row |
||
100 | if (!isset($option['hasHeader']) or $option['hasHeader'] !== 'false') { |
||
101 | $rows = array_slice($rows, 1); |
||
102 | } |
||
103 | |||
104 | $data = array(); |
||
105 | if (count($selectedColumns) !== 0) { |
||
106 | // if only a subset of columns or fixed column values are set, they are replaced here |
||
107 | $header = $this->minimizeRow($selectedColumns, $header); |
||
108 | foreach ($rows as $row) { |
||
109 | $data[] = $this->minimizeRow($selectedColumns, array_map('trim', str_getcsv($row, $delimiter))); |
||
110 | } |
||
111 | } else { |
||
112 | foreach ($rows as $row) { |
||
113 | $data[] = array_map('trim', str_getcsv($row, $delimiter)); |
||
114 | } |
||
115 | } |
||
116 | unset($rows); |
||
117 | |||
118 | return [ |
||
119 | 'header' => $header, |
||
120 | 'dimensions' => array_slice($header, 0, count($header) - 1), |
||
121 | 'data' => $data, |
||
122 | 'error' => $error, |
||
123 | ]; |
||
154 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths