Conditions | 6 |
Paths | 24 |
Total Lines | 73 |
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 |
||
12 | public function testIconSet(): void |
||
13 | { |
||
14 | $filename = 'tests/data/Reader/XLSX/conditionalFormattingIconSet.xlsx'; |
||
15 | $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx'); |
||
16 | $spreadsheet = $reader->load($filename); |
||
17 | $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx'); |
||
18 | $spreadsheet->disconnectWorksheets(); |
||
19 | $worksheet = $reloadedSpreadsheet->getActiveSheet(); |
||
20 | |||
21 | $columnIndex = 'A'; |
||
22 | foreach (IconSetValues::cases() as $iconSetValue) { |
||
23 | // styles |
||
24 | $styles = $worksheet->getConditionalStyles("{$columnIndex}2:{$columnIndex}11"); |
||
25 | self::assertCount(1, $styles); |
||
26 | |||
27 | // icon set |
||
28 | $iconSet = $styles[0]->getIconSet(); |
||
29 | self::assertNotNull($iconSet); |
||
30 | self::assertSame($iconSetValue, $iconSet->getIconSetType() ?? IconSetValues::ThreeTrafficLights1); |
||
31 | |||
32 | ++$columnIndex; |
||
33 | } |
||
34 | |||
35 | // icon set attributes |
||
36 | $columnIndex = 'A'; |
||
37 | foreach ( |
||
38 | [ |
||
39 | ['reverse' => false, 'showValue' => false], |
||
40 | ['reverse' => true, 'showValue' => false], |
||
41 | ['reverse' => false, 'showValue' => true], |
||
42 | ] as $expected |
||
43 | ) { |
||
44 | $styles = $worksheet->getConditionalStyles("{$columnIndex}2:{$columnIndex}11"); |
||
45 | $iconSet = $styles[0]->getIconSet(); |
||
46 | self::assertNotNull($iconSet); |
||
47 | self::assertSame($expected['reverse'], $iconSet->getReverse() ?? false); |
||
48 | self::assertSame($expected['showValue'], $iconSet->getShowValue() ?? true); |
||
49 | self::assertFalse($iconSet->getCustom() ?? false); |
||
50 | |||
51 | ++$columnIndex; |
||
52 | } |
||
53 | |||
54 | // cfvos |
||
55 | $columnIndex = 'A'; |
||
56 | foreach ( |
||
57 | [ |
||
58 | [['percent', '0', true], ['percent', '33', false], ['percent', '67', true]], |
||
59 | [['percent', '0', true], ['num', '3', false], ['num', '7', true]], |
||
60 | [['percent', '0', true], ['formula', '10/3', false], ['formula', '10/2', true]], |
||
61 | [['percent', '0', true], ['percentile', '33', false], ['percentile', '67', true]], |
||
62 | ] as $expected |
||
63 | ) { |
||
64 | $styles = $worksheet->getConditionalStyles("{$columnIndex}2:{$columnIndex}11"); |
||
65 | $iconSet = $styles[0]->getIconSet(); |
||
66 | self::assertNotNull($iconSet); |
||
67 | $cfvos = $iconSet->getCfvos(); |
||
68 | self::assertCount(count($expected), $cfvos); |
||
69 | foreach ($expected as $i => [$type, $value, $gte]) { |
||
70 | $cfvo = $cfvos[$i]; |
||
71 | self::assertSame($type, $cfvo->getType()); |
||
72 | self::assertSame($value, $cfvo->getValue()); |
||
73 | self::assertSame($gte, $cfvo->getGreaterThanOrEqual() ?? true); |
||
74 | self::assertNull($cfvo->getCellFormula()); |
||
75 | } |
||
76 | |||
77 | ++$columnIndex; |
||
78 | } |
||
79 | |||
80 | // unsupported icon sets |
||
81 | for ($columnIndex = 'R'; $columnIndex <= 'U'; ++$columnIndex) { |
||
82 | $styles = $worksheet->getConditionalStyles("{$columnIndex}2:{$columnIndex}11"); |
||
83 | $iconSet = $styles[0]->getIconSet(); |
||
84 | self::assertNull($iconSet); |
||
85 | } |
||
88 |