Conditions | 6 |
Paths | 6 |
Total Lines | 54 |
Code Lines | 38 |
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 |
||
175 | private function convertExcelDate($spreadsheet, $values, $range): array { |
||
176 | $map = [ |
||
177 | "yyyy" => "Y", // Four-digit year |
||
178 | "yy" => "y", // Two-digit year |
||
179 | "MM" => "m", // Two-digit month |
||
180 | "mm" => "i", // Two-digit minutes (lowercase) |
||
181 | "dd" => "d", // Two-digit day |
||
182 | "d" => "j", // Day without leading zeros |
||
183 | "hh" => "H", // 24-hour format |
||
184 | "h" => "G", // 12-hour format |
||
185 | "ss" => "s" // Seconds |
||
186 | ]; |
||
187 | |||
188 | $start = str_getcsv($range, ':'); |
||
189 | $startCell = Coordinate::coordinateFromString($start[0]); |
||
190 | $startColumn = (int)Coordinate::columnIndexFromString($startCell[0]); |
||
191 | $startRow = (int)$startCell[1]; |
||
192 | |||
193 | foreach ($values as $rowIndex => $row) { |
||
194 | foreach ($row as $columnIndex => $cellValue) { |
||
195 | $columnLetter = Coordinate::stringFromColumnIndex($columnIndex + $startColumn); |
||
196 | $rowNumber = $rowIndex + $startRow; |
||
197 | $coordinate = $columnLetter . $rowNumber; |
||
198 | $cell = $spreadsheet->getActiveSheet()->getCell($coordinate); |
||
199 | $excelFormat = $cell->getStyle()->getNumberFormat()->getFormatCode(); |
||
200 | |||
201 | if (preg_match('/%/', $excelFormat)) { |
||
202 | // Convert percentage to decimal value |
||
203 | $cellValue = $cell->getCalculatedValue(); |
||
204 | $values[$rowIndex][$columnIndex] = round($cellValue, 2); |
||
205 | } elseif (Date::isDateTime($cell)) { |
||
206 | $excelFormat = rtrim($excelFormat, ";@"); |
||
207 | |||
208 | // Check if it's a duration format (e.g., h:mm, [h]:mm, h:mm:ss) |
||
209 | if (preg_match('/[h]+:?[m]+:?[s]*/i', $excelFormat)) { |
||
210 | // Convert time duration to decimal |
||
211 | $excelTime = $cell->getCalculatedValue(); |
||
212 | $totalHours = Date::excelToDateTimeObject($excelTime)->format('G'); // Extract hours |
||
213 | $totalMinutes = Date::excelToDateTimeObject($excelTime)->format('i'); // Extract minutes |
||
214 | $totalSeconds = Date::excelToDateTimeObject($excelTime)->format('s'); // Extract seconds |
||
215 | |||
216 | // Convert the time to decimal (minutes) |
||
217 | $totalMinutesValue = ($totalHours * 60) + $totalMinutes + ($totalSeconds / 60); |
||
218 | $values[$rowIndex][$columnIndex] = round($totalMinutesValue, 2); // Rounded to 2 decimal places |
||
219 | } else { |
||
220 | // Regular date formatting |
||
221 | $date = Date::excelToDateTimeObject($cell->getCalculatedValue()); |
||
222 | $targetFormat = strtr($excelFormat, $map); |
||
223 | $values[$rowIndex][$columnIndex] = $date->format($targetFormat); |
||
224 | } |
||
225 | } |
||
226 | } |
||
227 | } |
||
228 | return $values; |
||
229 | } |
||
230 | } |
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