| Conditions | 8 |
| Paths | 32 |
| Total Lines | 57 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 77 | public function readData($option): array |
||
| 78 | { |
||
| 79 | include_once __DIR__ . '/../../vendor/autoload.php'; |
||
| 80 | $header = $dataClean = $data = array(); |
||
| 81 | $headerrow = $error = 0; |
||
| 82 | |||
| 83 | $file = $this->rootFolder->getUserFolder($option['user_id'])->get($option['link']); |
||
| 84 | $fileName = $file->getStorage()->getLocalFile($file->getInternalPath()); |
||
| 85 | |||
| 86 | $inputFileType = IOFactory::identify($fileName); |
||
| 87 | $reader = IOFactory::createReader($inputFileType); |
||
| 88 | //$reader->setReadDataOnly(true); disabled as idDate is not working otherwise |
||
| 89 | if (strlen($option['sheet']) > 0) { |
||
| 90 | $reader->setLoadSheetsOnly([$option['sheet']]); |
||
| 91 | } |
||
| 92 | $spreadsheet = $reader->load($fileName); |
||
| 93 | |||
| 94 | // separated columns can be selected via ranges e.g. "A1:B9,C1:C9" |
||
| 95 | // these ranges are read and linked |
||
| 96 | $ranges = str_getcsv($option['range']); |
||
| 97 | foreach ($ranges as $range) { |
||
| 98 | $values = $spreadsheet->getActiveSheet()->rangeToArray( |
||
| 99 | $range, // The worksheet range that we want to retrieve |
||
| 100 | NULL, // Value that should be returned for empty cells |
||
| 101 | TRUE, // Should formulas be calculated (the equivalent of getCalculatedValue() for each cell) |
||
| 102 | TRUE, // Should values be formatted (the equivalent of getFormattedValue() for each cell) |
||
| 103 | FALSE // Should the array be indexed by cell row and cell column |
||
| 104 | ); |
||
| 105 | |||
| 106 | $values = $this->convertExcelDate($spreadsheet, $values, $range); |
||
| 107 | |||
| 108 | if (empty($data)) { |
||
| 109 | // first range will fill the array with all rows |
||
| 110 | $data = $values; |
||
| 111 | } else { |
||
| 112 | // further columns will be attached to the first ones |
||
| 113 | foreach ($data as $key => $value) { |
||
| 114 | $data[$key] = array_merge($value, $values[$key]); |
||
| 115 | } |
||
| 116 | |||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | foreach ($data as $key => $value) { |
||
| 121 | if ($headerrow === 0) { |
||
| 122 | $header = array_values($value); |
||
| 123 | $headerrow = 1; |
||
| 124 | } else if (!$this->containsOnlyNull($value)) { |
||
| 125 | array_push($dataClean, array_values($value)); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | return [ |
||
| 130 | 'header' => $header, |
||
| 131 | 'dimensions' => array_slice($header, 0, count($header) - 1), |
||
| 132 | 'data' => $dataClean, |
||
| 133 | 'error' => $error, |
||
| 134 | ]; |
||
| 190 | } |
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