| Conditions | 4 |
| Paths | 5 |
| Total Lines | 61 |
| Code Lines | 41 |
| 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 |
||
| 26 | public function handle(GeneratorInterface $generator) |
||
| 27 | { |
||
| 28 | /** @scrutinizer ignore-call */ |
||
| 29 | $spreadsheet = $generator->getSpreadsheet(); |
||
| 30 | /** @scrutinizer ignore-call */ |
||
| 31 | $data = $generator->getData(); |
||
| 32 | /** @scrutinizer ignore-call */ |
||
| 33 | $properties = $generator->getProperties(); |
||
| 34 | /** @var AbstractProperty $property */ |
||
| 35 | $columns = 1; |
||
| 36 | foreach ($properties->getProperties() as $property) { |
||
| 37 | if (($width = $property->getWidth()) > 0) { |
||
| 38 | $spreadsheet->getActiveSheet() |
||
| 39 | ->getColumnDimension( |
||
| 40 | Coordinate::stringFromColumnIndex($columns) |
||
| 41 | )->setWidth($width); |
||
| 42 | } |
||
| 43 | |||
| 44 | if (($header = $property->getTitle()) !== '') { |
||
| 45 | $spreadsheet->getActiveSheet() |
||
| 46 | ->setCellValueByColumnAndRow($columns, 1, $header); |
||
| 47 | } |
||
| 48 | |||
| 49 | $columns++; |
||
| 50 | } |
||
| 51 | |||
| 52 | $highestRow = 1 + count($data); |
||
| 53 | $highestCol = count($properties->getProperties()); |
||
| 54 | |||
| 55 | $style = new Style(); |
||
| 56 | $style->getFont() |
||
| 57 | ->setName('Arial') |
||
| 58 | ->setSize(8); |
||
| 59 | |||
| 60 | $style->getBorders() |
||
| 61 | ->getLeft() |
||
| 62 | ->setBorderStyle(Border::BORDER_THIN); |
||
| 63 | |||
| 64 | $style->getBorders() |
||
| 65 | ->getRight() |
||
| 66 | ->setBorderStyle(Border::BORDER_THIN); |
||
| 67 | |||
| 68 | $style->getBorders() |
||
| 69 | ->getBottom() |
||
| 70 | ->setBorderStyle(Border::BORDER_THIN); |
||
| 71 | |||
| 72 | $style->getBorders() |
||
| 73 | ->getTop() |
||
| 74 | ->setBorderStyle(Border::BORDER_THIN); |
||
| 75 | |||
| 76 | $style->getAlignment() |
||
| 77 | ->setWrapText(true) |
||
| 78 | ->setShrinkToFit(true) |
||
| 79 | ->setHorizontal(Alignment::HORIZONTAL_CENTER) |
||
| 80 | ->setVertical(Alignment::VERTICAL_CENTER); |
||
| 81 | |||
| 82 | $col = Coordinate::stringFromColumnIndex($highestCol); |
||
| 83 | |||
| 84 | $spreadsheet->getActiveSheet() |
||
| 85 | ->duplicateStyle($style, sprintf("A1:%s%d", $col, $highestRow)); |
||
| 86 | return parent::handle($generator); |
||
| 87 | } |
||
| 89 |