Conditions | 3 |
Paths | 1 |
Total Lines | 55 |
Code Lines | 51 |
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 |
||
25 | public function testStyles(): void |
||
26 | { |
||
27 | $file = 'tests/data/Reader/XLSX/issue.4248.xlsx'; |
||
28 | $reader = new XlsxReader(); |
||
29 | $spreadsheet = $reader->load($file); |
||
30 | $writer = new XlsxWriter($spreadsheet); |
||
31 | $this->outfile = File::temporaryFilename(); |
||
32 | $writer->save($this->outfile); |
||
33 | $spreadsheet->disconnectWorksheets(); |
||
34 | |||
35 | $file = 'zip://'; |
||
36 | $file .= $this->outfile; |
||
37 | $file .= '#xl/styles.xml'; |
||
38 | $data = file_get_contents($file) ?: ''; |
||
39 | $expected = '<fill>' |
||
40 | . '<patternFill patternType="darkDown"/>' |
||
41 | . '</fill>'; |
||
42 | self::assertStringContainsString($expected, $data, 'neither fgColor nor bgColor'); |
||
43 | $expected = '<fill>' |
||
44 | . '<patternFill patternType="darkDown">' |
||
45 | . '<bgColor rgb="FFBDD7EE"/>' |
||
46 | . '</patternFill></fill>'; |
||
47 | self::assertStringContainsString($expected, $data, 'bgColor but no fgColor'); |
||
48 | $expected = '<dxfs count="15">' |
||
49 | . '<dxf>' // dxfId 1 - fill color for Oui |
||
50 | . '<fill>' |
||
51 | . '<patternFill><bgColor rgb="FF00B050"/></patternFill>' |
||
52 | . '</fill>' |
||
53 | . '<border/>' |
||
54 | . '</dxf>' |
||
55 | . '<dxf>' // dxfId 2 - fill color for Non |
||
56 | . '<font><color rgb="FF9C0006"/></font>' |
||
57 | . '<fill>' |
||
58 | . '<patternFill><bgColor rgb="FFFFC7CE"/></patternFill>' |
||
59 | . '</fill>' |
||
60 | . '<border/>' |
||
61 | . '</dxf>'; |
||
62 | self::assertStringContainsString($expected, $data, 'conditional fill styles'); |
||
63 | |||
64 | $file = 'zip://'; |
||
65 | $file .= $this->outfile; |
||
66 | $file .= '#xl/worksheets/sheet1.xml'; |
||
67 | $data = file_get_contents($file) ?: ''; |
||
68 | $expected = '<conditionalFormatting sqref="C16:C38 E17:H18 I17:J37 D18 J23:J38 E38 I38">' |
||
69 | . '<cfRule type="containsText" dxfId="0" priority="1" operator="containsText" text="Oui">' |
||
70 | . '<formula>NOT(ISERROR(SEARCH("Oui",C16)))</formula>' |
||
71 | . '</cfRule>' |
||
72 | . '</conditionalFormatting>'; |
||
73 | self::assertStringContainsString($expected, $data, 'first condition for D18'); |
||
74 | $expected = '<conditionalFormatting sqref="C16:C38 I17:J37 E17:H18 D18 J23:J38 E38 I38">' |
||
75 | . '<cfRule type="containsText" dxfId="1" priority="2" operator="containsText" text="Non">' |
||
76 | . '<formula>NOT(ISERROR(SEARCH("Non",C16)))</formula>' |
||
77 | . '</cfRule>' |
||
78 | . '</conditionalFormatting>'; |
||
79 | self::assertStringContainsString($expected, $data, 'second condition for D18'); |
||
80 | } |
||
105 |