Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
Code Lines | 36 |
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 |
||
13 | public function testNonLatin(): void |
||
14 | { |
||
15 | $spreadsheet = new Spreadsheet(); |
||
16 | $worksheet = $spreadsheet->getActiveSheet(); |
||
17 | |||
18 | $validation = $worksheet->getCell('B1')->getDataValidation(); |
||
19 | $validation->setType(DataValidation::TYPE_LIST); |
||
20 | $validation->setErrorStyle(DataValidation::STYLE_STOP); |
||
21 | $validation->setAllowBlank(false); |
||
22 | $validation->setShowInputMessage(true); |
||
23 | $validation->setShowErrorMessage(true); |
||
24 | $validation->setShowDropDown(true); |
||
25 | $validation->setFormula1('"слово, сло"'); |
||
26 | |||
27 | $dataValidator = new DataValidator(); |
||
28 | $worksheet->getCell('B1')->setValue('слово'); |
||
29 | self::assertTrue( |
||
30 | $dataValidator->isValid($worksheet->getCell('B1')) |
||
31 | ); |
||
32 | $worksheet->getCell('B1')->setValue('слов'); |
||
33 | self::assertFalse( |
||
34 | $dataValidator->isValid($worksheet->getCell('B1')) |
||
35 | ); |
||
36 | |||
37 | $worksheet->setTitle('словслов'); |
||
38 | $worksheet->getCell('A1')->setValue('=словслов!B1'); |
||
39 | $worksheet->getCell('A2')->setValue("='словслов'!B1"); |
||
40 | $spreadsheet->addNamedRange(new NamedRange('слсл', $worksheet, '$B$1')); |
||
41 | $worksheet->getCell('A3')->setValue('=слсл'); |
||
42 | |||
43 | $robj = $this->writeAndReload($spreadsheet, 'Xls'); |
||
44 | $spreadsheet->disconnectWorksheets(); |
||
45 | $sheet0 = $robj->getActiveSheet(); |
||
46 | self::assertSame('словслов', $sheet0->getTitle()); |
||
47 | self::assertSame('=словслов!B1', $sheet0->getCell('A1')->getValue()); |
||
48 | self::assertSame('слов', $sheet0->getCell('A1')->getCalculatedValue()); |
||
49 | // Quotes around sheet name are stripped off - harmless |
||
50 | //self::assertSame("='словслов'!B1", $sheet0->getCell('A2')->getValue()); |
||
51 | self::assertSame('слов', $sheet0->getCell('A2')->getCalculatedValue()); |
||
52 | // Formulas with defined names don't work in Xls Writer |
||
53 | //self::assertSame('=слсл', $sheet0->getCell('A3')->getValue()); |
||
54 | // But result should be accurate |
||
55 | self::assertSame('слов', $sheet0->getCell('A3')->getCalculatedValue()); |
||
56 | $names = $robj->getDefinedNames(); |
||
57 | self::assertCount(1, $names); |
||
58 | // name has been uppercased |
||
59 | $namedRange = $names['СЛСЛ'] ?? null; |
||
60 | self::assertInstanceOf(NamedRange::class, $namedRange); |
||
61 | self::assertSame('$B$1', $namedRange->getRange()); |
||
62 | |||
63 | $robj->disconnectWorksheets(); |
||
64 | } |
||
66 |