Conditions | 1 |
Paths | 1 |
Total Lines | 101 |
Code Lines | 92 |
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 |
||
97 | public function testRichText() |
||
98 | { |
||
99 | $spreadsheet = new Spreadsheet(); |
||
100 | $sheet = $spreadsheet->getActiveSheet(); |
||
101 | $emc2 = new \PhpOffice\PhpSpreadsheet\RichText\RichText(); |
||
102 | $part1 = $emc2->createTextRun('e=mc'); |
||
103 | $part1->getFont()->getColor()->setARGB(Color::COLOR_BLUE); |
||
104 | $part2 = $emc2->createTextRun('2'); |
||
105 | $font = $part2->getFont(); |
||
106 | $font->getColor()->setARGB(Color::COLOR_DARKGREEN); |
||
107 | $font->setSuperScript(true); |
||
108 | $sheet->setCellValue('A1', $emc2); |
||
109 | $h2o = new \PhpOffice\PhpSpreadsheet\RichText\RichText(); |
||
110 | $h2o->createTextRun('H'); |
||
111 | $part2 = $h2o->createTextRun('2'); |
||
112 | $font = $part2->getFont(); |
||
113 | $font->setSubScript(true); |
||
114 | $font->getColor()->setARGB(Color::COLOR_RED); |
||
115 | $h2o->createTextRun('O'); |
||
116 | $sheet->setCellValue('A2', $h2o); |
||
117 | $h2so4 = new \PhpOffice\PhpSpreadsheet\RichText\RichText(); |
||
118 | $h2so4->createTextRun('H'); |
||
119 | $part2 = $h2so4->createTextRun('2'); |
||
120 | $font = $part2->getFont(); |
||
121 | $font->setSubScript(true); |
||
122 | $h2so4->createTextRun('SO'); |
||
123 | $part4 = $h2so4->createTextRun('4'); |
||
124 | $part4->getFont()->setSubScript(true); |
||
125 | $sheet->setCellValue('A3', $h2so4); |
||
126 | $sheet->setCellValue('A4', '5'); |
||
127 | $sheet->getCell('A4')->getStyle()->getFont()->setSuperScript(true); |
||
128 | $sheet->setCellValue('A5', '6'); |
||
129 | $sheet->getCell('A5')->getStyle()->getFont()->setSubScript(true); |
||
130 | |||
131 | $writer = new Html($spreadsheet); |
||
132 | $html = $writer->generateHTMLAll(); |
||
133 | $dom = new \DOMDocument(); |
||
134 | $dom->loadHTML($html); |
||
135 | $body = $dom->getElementsByTagName('body')[0]; |
||
136 | $divs = $body->getElementsByTagName('div'); |
||
137 | self::assertCount(1, $divs); |
||
138 | |||
139 | $tabl = $divs[0]->getElementsByTagName('table'); |
||
140 | $tbod = $tabl[0]->getElementsByTagName('tbody'); |
||
141 | $rows = $tbod[0]->getElementsByTagName('tr'); |
||
142 | self::assertCount(5, $rows); |
||
143 | $tds = $rows[0]->getElementsByTagName('td'); |
||
144 | self::assertCount(1, $tds); |
||
145 | $spans = $tds[0]->getElementsByTagName('span'); |
||
146 | self::assertCount(2, $spans); |
||
147 | self::assertEquals('e=mc', $spans[0]->textContent); |
||
148 | $style = $spans[0]->getAttribute('style'); |
||
149 | self::assertEquals(1, preg_match('/color:#0000FF/', $style)); |
||
150 | $style = $spans[1]->getAttribute('style'); |
||
151 | self::assertEquals(1, preg_match('/color:#008000/', $style)); |
||
152 | $sups = $spans[1]->getElementsByTagName('sup'); |
||
153 | self::assertCount(1, $sups); |
||
154 | assert('2' == $sups[0]->textContent); |
||
155 | |||
156 | $tds = $rows[1]->getElementsByTagName('td'); |
||
157 | assert(1 == count($tds)); |
||
158 | $spans = $tds[0]->getElementsByTagName('span'); |
||
159 | assert(3 == count($spans)); |
||
160 | assert('H' == $spans[0]->textContent); |
||
161 | $style = $spans[1]->getAttribute('style'); |
||
162 | assert(1 == preg_match('/color:#FF0000/', $style)); |
||
163 | $subs = $spans[1]->getElementsByTagName('sub'); |
||
164 | assert(1 == count($subs)); |
||
165 | assert('2' == $subs[0]->textContent); |
||
166 | assert('O' == $spans[2]->textContent); |
||
167 | |||
168 | $tds = $rows[2]->getElementsByTagName('td'); |
||
169 | self::assertCount(1, $tds); |
||
170 | $spans = $tds[0]->getElementsByTagName('span'); |
||
171 | self::assertCount(4, $spans); |
||
172 | self::assertEquals('H', $spans[0]->textContent); |
||
173 | $subs = $spans[1]->getElementsByTagName('sub'); |
||
174 | self::assertCount(1, $subs); |
||
175 | self::assertEquals('2', $subs[0]->textContent); |
||
176 | self::assertEquals('SO', $spans[2]->textContent); |
||
177 | $subs = $spans[3]->getElementsByTagName('sub'); |
||
178 | self::assertCount(1, $subs); |
||
179 | self::assertEquals('4', $subs[0]->textContent); |
||
180 | |||
181 | $tds = $rows[3]->getElementsByTagName('td'); |
||
182 | self::assertCount(1, $tds); |
||
183 | $spans = $tds[0]->getElementsByTagName('span'); |
||
184 | self::assertCount(0, $spans); |
||
185 | $sups = $tds[0]->getElementsByTagName('sup'); |
||
186 | self::assertCount(1, $sups); |
||
187 | self::assertEquals('5', $sups[0]->textContent); |
||
188 | |||
189 | $tds = $rows[4]->getElementsByTagName('td'); |
||
190 | self::assertCount(1, $tds); |
||
191 | $spans = $tds[0]->getElementsByTagName('span'); |
||
192 | self::assertCount(0, $spans); |
||
193 | $subs = $tds[0]->getElementsByTagName('sub'); |
||
194 | self::assertCount(1, $subs); |
||
195 | self::assertEquals('6', $subs[0]->textContent); |
||
196 | |||
197 | $this->writeAndReload($spreadsheet, 'Html'); |
||
198 | } |
||
200 |