Conditions | 1 |
Paths | 1 |
Total Lines | 61 |
Code Lines | 50 |
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 |
||
113 | public static function testTables(): void |
||
114 | { |
||
115 | $spreadsheet = new Spreadsheet(); |
||
116 | Calculation::getInstance($spreadsheet) |
||
117 | ->setInstanceArrayReturnType( |
||
118 | Calculation::RETURN_ARRAY_AS_ARRAY |
||
119 | ); |
||
120 | $sheet = $spreadsheet->getActiveSheet(); |
||
121 | |||
122 | $data = [ |
||
123 | ['Date', 'Color', 'Qty'], |
||
124 | [Date::stringToExcel('2021-04-03'), 'Red', 12], |
||
125 | [Date::stringToExcel('2021-04-07'), 'Blue', 9], |
||
126 | [Date::stringToExcel('2021-04-11'), 'Green', 10], |
||
127 | [Date::stringToExcel('2021-04-15'), 'Blue', 11], |
||
128 | [Date::stringToExcel('2021-04-20'), 'Red', 8], |
||
129 | ]; |
||
130 | $sheet->fromArray($data, null, 'B4', true); |
||
131 | $table = new Table('B4:D9', 'Table1'); |
||
132 | $sheet->addTable($table); |
||
133 | |||
134 | $data = [ |
||
135 | ['Date', 'Color', 'Qty'], |
||
136 | [Date::stringToExcel('2021-05-05'), 'Red', 12], |
||
137 | [Date::stringToExcel('2021-05-12'), 'Blue', 9], |
||
138 | [Date::stringToExcel('2021-05-18'), 'Green', 10], |
||
139 | [Date::stringToExcel('2021-05-21'), 'Blue', 11], |
||
140 | [Date::stringToExcel('2021-05-28'), 'Green', 6], |
||
141 | ]; |
||
142 | $sheet->fromArray($data, null, 'B11', true); |
||
143 | $table = new Table('B11:D16', 'Table2'); |
||
144 | $sheet->addTable($table); |
||
145 | |||
146 | $sheet->setCellValue('G4', 'Date'); |
||
147 | $sheet->setCellValue('H4', 'Color'); |
||
148 | $sheet->setCellValue('I4', 'Qty'); |
||
149 | $sheet->setCellValue('G5', '=VSTACK(Table1[],Table2[])'); |
||
150 | $sheet->getCell('G5')->getCalculatedValue(); |
||
151 | |||
152 | $sheet->getStyle('B4:B16') |
||
153 | ->getNumberFormat() |
||
154 | ->setFormatCode('d-mmm'); |
||
155 | $sheet->getStyle('G5:G14') |
||
156 | ->getNumberFormat() |
||
157 | ->setFormatCode('d-mmm'); |
||
158 | $expected = [ |
||
159 | ['3-Apr', 'Red', '12'], |
||
160 | ['7-Apr', 'Blue', '9'], |
||
161 | ['11-Apr', 'Green', '10'], |
||
162 | ['15-Apr', 'Blue', '11'], |
||
163 | ['20-Apr', 'Red', '8'], |
||
164 | ['5-May', 'Red', '12'], |
||
165 | ['12-May', 'Blue', '9'], |
||
166 | ['18-May', 'Green', '10'], |
||
167 | ['21-May', 'Blue', '11'], |
||
168 | ['28-May', 'Green', '6'], |
||
169 | ]; |
||
170 | $actual = $sheet->rangeToArray('G5:I14', null, true, true); |
||
171 | self::assertSame($expected, $actual); |
||
172 | |||
173 | $spreadsheet->disconnectWorksheets(); |
||
174 | } |
||
176 |