Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
14 | public function testApostropheInSheetName(): void |
||
15 | { |
||
16 | $spreadsheet = new Spreadsheet(); |
||
17 | Calculation::getInstance($spreadsheet) |
||
18 | ->setInstanceArrayReturnType( |
||
19 | Calculation::RETURN_ARRAY_AS_ARRAY |
||
20 | ); |
||
21 | $sheet = $spreadsheet->getActiveSheet(); |
||
22 | $sheet->setTitle('sheet1'); |
||
23 | $sheet->getCell('A1')->setValue(1); |
||
24 | $sheet->getCell('A2')->setValue(2); |
||
25 | $sheet->getCell('A3')->setValue(3); |
||
26 | $sheet->getCell('A4')->setValue(4); |
||
27 | $spreadsheet->addNamedRange(new NamedRange('sheet14cells', $sheet, '$A$1:$A$4')); |
||
28 | $sheet->getCell('C1') |
||
29 | ->setValue('=sheet14cells*sheet14cells'); |
||
30 | $sheet->getCell('E1')->setValue('=ANCHORARRAY(sheet1!C1)'); |
||
31 | $sheet->getCell('G1')->setValue('=SINGLE(sheet1!C1:C4)'); |
||
32 | |||
33 | $sheet1 = $spreadsheet->createSheet(); |
||
34 | $sheet1->setTitle("Apo'strophe"); |
||
35 | $sheet1->getCell('A1')->setValue(2); |
||
36 | $sheet1->getCell('A2')->setValue(3); |
||
37 | $sheet1->getCell('A3')->setValue(4); |
||
38 | $sheet1->getCell('A4')->setValue(5); |
||
39 | $spreadsheet->addNamedRange(new NamedRange('sheet24cells', $sheet1, '$A$1:$A$4')); |
||
40 | $sheet1->getCell('C1') |
||
41 | ->setValue('=sheet24cells*sheet24cells'); |
||
42 | $sheet1->getCell('E1')->setValue("=ANCHORARRAY('Apo''strophe'!C1)"); |
||
43 | $sheet1->getCell('G1')->setValue("=SINGLE('Apo''strophe'!C1:C4)"); |
||
44 | |||
45 | $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx'); |
||
46 | $spreadsheet->disconnectWorksheets(); |
||
47 | Calculation::getInstance($reloadedSpreadsheet) |
||
48 | ->setInstanceArrayReturnType( |
||
49 | Calculation::RETURN_ARRAY_AS_ARRAY |
||
50 | ); |
||
51 | $rsheet = $reloadedSpreadsheet->getSheet(0); |
||
52 | // make sure results aren't from cache |
||
53 | $rsheet->getCell('E1')->setCalculatedValue(-1); |
||
54 | $rsheet->getCell('G1')->setCalculatedValue(-1); |
||
55 | self::assertSame([[1], [4], [9], [16]], $rsheet->getCell('C1')->getCalculatedValue()); |
||
56 | self::assertSame([[1], [4], [9], [16]], $rsheet->getCell('E1')->getCalculatedValue()); |
||
57 | self::assertSame(1, $rsheet->getCell('G1')->getCalculatedValue()); |
||
58 | |||
59 | $rsheet1 = $reloadedSpreadsheet->getSheet(1); |
||
60 | // make sure results aren't from cache |
||
61 | $rsheet1->getCell('E1')->setCalculatedValue(-1); |
||
62 | $rsheet1->getCell('G1')->setCalculatedValue(-1); |
||
63 | self::assertSame([[4], [9], [16], [25]], $rsheet1->getCell('C1')->getCalculatedValue()); |
||
64 | self::assertSame([[4], [9], [16], [25]], $rsheet1->getCell('E1')->getCalculatedValue()); |
||
65 | self::assertSame(4, $rsheet1->getCell('G1')->getCalculatedValue()); |
||
66 | $reloadedSpreadsheet->disconnectWorksheets(); |
||
67 | } |
||
69 |