| Conditions | 10 |
| Paths | 34 |
| Total Lines | 64 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 201 | public function parse() |
||
| 202 | { |
||
| 203 | if ('' === $this->html) { |
||
| 204 | return null; |
||
| 205 | } |
||
| 206 | $this->html = $this->removeComments($this->html); |
||
| 207 | $this->htmlPageGroups = $this->getHtmlPageGroups($this->html); |
||
| 208 | foreach ($this->htmlPageGroups as $groupIndex => $htmlPageGroup) { |
||
| 209 | $domDocument = new \DOMDocument(); |
||
| 210 | $domDocument->encoding = 'UTF-8'; |
||
| 211 | $domDocument->strictErrorChecking = false; |
||
| 212 | $domDocument->substituteEntities = false; |
||
| 213 | $domDocument->recover = false; |
||
| 214 | $domDocument->loadHTML('<div id="yetiforcepdf">' . $htmlPageGroup . '</div>', LIBXML_HTML_NOIMPLIED | LIBXML_NOWARNING | LIBXML_NOBLANKS | LIBXML_NOERROR); |
||
| 215 | $pageGroup = (new PageGroupBox()) |
||
| 216 | ->setDocument($this->document) |
||
| 217 | ->setRoot(true) |
||
| 218 | ->init(); |
||
| 219 | $pageGroup->format = $this->document->getDefaultFormat(); |
||
| 220 | $margins = $this->document->getDefaultMargins(); |
||
| 221 | $pageGroup->marginLeft = $margins['left']; |
||
| 222 | $pageGroup->marginTop = $margins['top']; |
||
| 223 | $pageGroup->marginRight = $margins['right']; |
||
| 224 | $pageGroup->marginBottom = $margins['bottom']; |
||
| 225 | $pageGroup->orientation = $this->document->getDefaultOrientation(); |
||
| 226 | $this->setGroupOptions($pageGroup, $domDocument); |
||
| 227 | $page = $this->document->addPage($pageGroup->format, $pageGroup->orientation); |
||
| 228 | $page->setPageNumber(1); |
||
| 229 | $page->setGroup($groupIndex); |
||
| 230 | $page->setMargins($pageGroup->marginLeft, $pageGroup->marginTop, $pageGroup->marginRight, $pageGroup->marginBottom); |
||
| 231 | $rootElement = (new \YetiForcePDF\Html\Element()) |
||
| 232 | ->setDocument($this->document) |
||
| 233 | ->setDOMElement($domDocument->documentElement); |
||
| 234 | // root element must be defined before initialisation |
||
| 235 | $rootElement->init(); |
||
| 236 | $pageGroup->setElement($rootElement); |
||
| 237 | $pageGroup->setStyle($rootElement->parseStyle()); |
||
| 238 | |||
| 239 | $pageGroup->buildTree(); |
||
| 240 | $pageGroup->fixTables(); |
||
| 241 | $pageGroup->getStyle()->fixDomTree(); |
||
| 242 | $pageGroup->layout(); |
||
| 243 | $page->setBox($pageGroup); |
||
| 244 | |||
| 245 | foreach ($this->document->getPages($groupIndex) as $page) { |
||
| 246 | $page->getBox()->breakPageAfter(); |
||
|
|
|||
| 247 | } |
||
| 248 | foreach ($this->document->getPages($groupIndex) as $page) { |
||
| 249 | $page->getBox()->spanAllRows(); |
||
| 250 | } |
||
| 251 | foreach ($this->document->getPages($groupIndex) as $page) { |
||
| 252 | $page->breakOverflow(); |
||
| 253 | } |
||
| 254 | $page->getBox()->getStyle()->fixDomTree(); |
||
| 255 | $this->document->fixPageNumbers(); |
||
| 256 | foreach ($this->document->getPages($groupIndex) as $page) { |
||
| 257 | $this->document->setCurrentPage($page); |
||
| 258 | $children = []; |
||
| 259 | $page->setUpAbsoluteBoxes(); |
||
| 260 | $page->getBox()->replacePageNumbers(); |
||
| 261 | $page->getBox()->getAllChildren($children); |
||
| 262 | foreach ($children as $box) { |
||
| 263 | if (!$box instanceof \YetiForcePDF\Layout\LineBox && $box->isRenderable()) { |
||
| 264 | $page->getContentStream()->addRawContent($box->getInstructions()); |
||
| 265 | } |
||
| 271 |