Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 35 |
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 |
||
54 | public function testWriteSpreadsheet(): void |
||
55 | { |
||
56 | $workbook = new Spreadsheet(); |
||
57 | |||
58 | // Worksheet 1 |
||
59 | $worksheet1 = $workbook->getActiveSheet(); |
||
60 | $worksheet1->setCellValue('A1', 1); // Number |
||
61 | $worksheet1->setCellValue('B1', 12345.6789); // Number |
||
62 | $worksheet1->setCellValue('C1', '1'); // Number without cast |
||
63 | $worksheet1->setCellValueExplicit('D1', '01234', DataType::TYPE_STRING); // Number casted to string |
||
64 | $worksheet1->setCellValue('E1', 'Lorem ipsum'); // String |
||
65 | |||
66 | $worksheet1->setCellValue('A2', true); // Boolean |
||
67 | $worksheet1->setCellValue('B2', false); // Boolean |
||
68 | |||
69 | $worksheet1->setCellValueExplicit( |
||
70 | 'C2', |
||
71 | '=IF(A3, CONCATENATE(A1, " ", A2), CONCATENATE(A2, " ", A1))', |
||
72 | DataType::TYPE_FORMULA |
||
73 | ); // Formula |
||
74 | |||
75 | $worksheet1->setCellValue('D2', Date::PHPToExcel(1488635026)); // Date |
||
76 | $worksheet1->getStyle('D2') |
||
77 | ->getNumberFormat() |
||
78 | ->setFormatCode(NumberFormat::FORMAT_DATE_DATETIME); |
||
79 | |||
80 | $worksheet1->setCellValueExplicit('F1', null, DataType::TYPE_ERROR); |
||
81 | $worksheet1->setCellValueExplicit('G1', 'Lorem ipsum', DataType::TYPE_INLINE); |
||
82 | |||
83 | // Styles |
||
84 | $worksheet1->getStyle('A1')->getFont()->setBold(true); |
||
85 | $worksheet1->getStyle('B1')->getFont()->setItalic(true); |
||
86 | $worksheet1->getStyle('C1')->getFont()->setName('Courier'); |
||
87 | $worksheet1->getStyle('C1')->getFont()->setSize(14); |
||
88 | $worksheet1->getStyle('C1')->getFont()->setColor(new Color(Color::COLOR_BLUE)); |
||
89 | |||
90 | $worksheet1->getStyle('C1')->getFill()->setFillType(Fill::FILL_SOLID); |
||
91 | $worksheet1->getStyle('C1')->getFill()->setStartColor(new Color(Color::COLOR_RED)); |
||
92 | |||
93 | $worksheet1->getStyle('C1')->getFont()->setUnderline(Font::UNDERLINE_SINGLE); |
||
94 | $worksheet1->getStyle('C2')->getFont()->setUnderline(Font::UNDERLINE_DOUBLE); |
||
95 | $worksheet1->getStyle('D2')->getFont()->setUnderline(Font::UNDERLINE_NONE); |
||
96 | |||
97 | // Worksheet 2 |
||
98 | $worksheet2 = $workbook->createSheet(); |
||
99 | $worksheet2->setTitle('New Worksheet'); |
||
100 | $worksheet2->setCellValue('A1', 2); |
||
101 | |||
102 | // Write |
||
103 | $content = new Content(new Ods($workbook)); |
||
104 | $xml = $content->write(); |
||
105 | |||
106 | self::assertXmlStringEqualsXmlFile($this->samplesPath . '/content-with-data.xml', $xml); |
||
107 | } |
||
168 |