Conditions | 1 |
Paths | 1 |
Total Lines | 70 |
Code Lines | 57 |
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 |
||
15 | public function testLimits(): void |
||
16 | { |
||
17 | $spreadsheet = new Spreadsheet(); |
||
18 | $sheet = $spreadsheet->getActiveSheet(); |
||
19 | $sheet->fromArray( |
||
20 | [ |
||
21 | ['Cell', 0, null, null, 'Col Rng', -2, -1], |
||
22 | [null, null, null, null, null, 0, 1], |
||
23 | ['Cell Rng', -2, -1, 0, null, 2, 3], |
||
24 | [null, 1, 2, 3, null, 4, -1], |
||
25 | [], |
||
26 | ['Row Rng'], |
||
27 | [-2, -1, 0], |
||
28 | [1, 2, 3], |
||
29 | ], |
||
30 | strictNullComparison: true |
||
31 | ); |
||
32 | $redStyle = new Style(false, true); |
||
33 | $redStyle->getFont()->setColor(new Color(Color::COLOR_RED)); |
||
34 | |||
35 | $condition1 = new Conditional(); |
||
36 | $condition1->setConditionType(Conditional::CONDITION_CELLIS) |
||
37 | ->setOperatorType(Conditional::OPERATOR_BETWEEN) |
||
38 | ->addCondition(-1) |
||
39 | ->addCondition(1) |
||
40 | ->setStyle($redStyle); |
||
41 | $conditionalStyles = [$condition1]; |
||
42 | $cellRange = 'B1'; |
||
43 | $sheet->getStyle($cellRange)->setConditionalStyles($conditionalStyles); |
||
44 | |||
45 | $condition2 = new Conditional(); |
||
46 | $condition2->setConditionType(Conditional::CONDITION_CELLIS) |
||
47 | ->setOperatorType(Conditional::OPERATOR_BETWEEN) |
||
48 | ->addCondition(-1.5) |
||
49 | ->addCondition(1.5) |
||
50 | ->setStyle($redStyle); |
||
51 | $conditionalStyles = [$condition2]; |
||
52 | $cellRange = 'F:G'; |
||
53 | $sheet->getStyle($cellRange)->setConditionalStyles($conditionalStyles); |
||
54 | |||
55 | $condition3 = new Conditional(); |
||
56 | $condition3->setConditionType(Conditional::CONDITION_CELLIS) |
||
57 | ->setOperatorType(Conditional::OPERATOR_BETWEEN) |
||
58 | ->addCondition(-1) |
||
59 | ->addCondition(70000) |
||
60 | ->setStyle($redStyle); |
||
61 | $conditionalStyles = [$condition3]; |
||
62 | $cellRange = '7:8'; |
||
63 | $sheet->getStyle($cellRange)->setConditionalStyles($conditionalStyles); |
||
64 | |||
65 | $cellRange = 'B3:D4'; |
||
66 | $sheet->getStyle($cellRange)->setConditionalStyles($conditionalStyles); |
||
67 | $sheet->setSelectedCells('A1'); |
||
68 | $keys = array_keys($sheet->getConditionalStylesCollection()); |
||
69 | self::assertSame(['B1', 'F1:G1048576', 'A7:XFD8', 'B3:D4'], $keys); |
||
70 | |||
71 | $robj = $this->writeAndReload($spreadsheet, 'Xls'); |
||
72 | $spreadsheet->disconnectWorksheets(); |
||
73 | $sheet0 = $robj->getActiveSheet(); |
||
74 | $conditionals = $sheet0->getConditionalStylesCollection(); |
||
75 | self::assertSame(['B1', 'F1:G65536', 'A7:IV8', 'B3:D4'], array_keys($conditionals)); |
||
76 | $b1 = $conditionals['B1'][0]; |
||
77 | self::assertSame([-1, 1], $b1->getConditions()); |
||
78 | $b1 = $conditionals['F1:G65536'][0]; |
||
79 | self::assertSame([-1.5, 1.5], $b1->getConditions()); |
||
80 | $b1 = $conditionals['A7:IV8'][0]; |
||
81 | self::assertSame([-1, 70000], $b1->getConditions()); |
||
82 | $b1 = $conditionals['B3:D4'][0]; |
||
83 | self::assertSame([-1, 70000], $b1->getConditions()); |
||
84 | $robj->disconnectWorksheets(); |
||
85 | } |
||
87 |