| Conditions | 26 |
| Paths | 4 |
| Total Lines | 90 |
| Code Lines | 66 |
| 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 |
||
| 203 | public function buildTree($parentBlock = null) |
||
| 204 | { |
||
| 205 | if ($this->getElement()) { |
||
| 206 | $domElement = $this->getElement()->getDOMElement(); |
||
| 207 | } else { |
||
| 208 | // tablebox doesn't have element so we can get it from table wrapper (parent box) |
||
| 209 | $domElement = $this->getParent()->getElement()->getDOMElement(); |
||
|
|
|||
| 210 | } |
||
| 211 | if ($domElement->hasChildNodes()) { |
||
| 212 | foreach ($domElement->childNodes as $childDomElement) { |
||
| 213 | if ($childDomElement instanceof \DOMComment) { |
||
| 214 | continue; |
||
| 215 | } |
||
| 216 | |||
| 217 | $element = (new Element()) |
||
| 218 | ->setDocument($this->document) |
||
| 219 | ->setDOMElement($childDomElement) |
||
| 220 | ->init(); |
||
| 221 | $style = (new \YetiForcePDF\Style\Style()) |
||
| 222 | ->setDocument($this->document) |
||
| 223 | ->setElement($element); |
||
| 224 | if ($childDomElement instanceof \DOMElement) { |
||
| 225 | if ($childDomElement->hasAttribute('style')) { |
||
| 226 | // for now only basic style is used - from current element only (with defaults) |
||
| 227 | $style->setContent($childDomElement->getAttribute('style')); |
||
| 228 | } elseif ('style' === $childDomElement->nodeName) { |
||
| 229 | $style->parseCss($childDomElement->nodeValue); |
||
| 230 | } |
||
| 231 | $element->attachClasses(); |
||
| 232 | } |
||
| 233 | $style = $style->parseInline(); |
||
| 234 | $display = $style->getRules('display'); |
||
| 235 | switch ($display) { |
||
| 236 | case 'block': |
||
| 237 | if ($childDomElement->hasAttribute('data-header')) { |
||
| 238 | $this->appendHeaderBox($childDomElement, $element, $style, $parentBlock); |
||
| 239 | } elseif ($childDomElement->hasAttribute('data-footer')) { |
||
| 240 | $this->appendFooterBox($childDomElement, $element, $style, $parentBlock); |
||
| 241 | } elseif ($childDomElement->hasAttribute('data-watermark')) { |
||
| 242 | $this->appendWatermarkBox($childDomElement, $element, $style, $parentBlock); |
||
| 243 | } elseif ($childDomElement->hasAttribute('data-font')) { |
||
| 244 | $this->appendFontBox($childDomElement, $element, $style, $parentBlock); |
||
| 245 | } elseif ($childDomElement->hasAttribute('data-barcode')) { |
||
| 246 | $this->appendBarcodeBox($childDomElement, $element, $style, $parentBlock); |
||
| 247 | } else { |
||
| 248 | $this->appendBlockBox($childDomElement, $element, $style, $parentBlock); |
||
| 249 | } |
||
| 250 | |||
| 251 | break; |
||
| 252 | case 'table': |
||
| 253 | $tableWrapper = $this->appendTableWrapperBox($childDomElement, $element, $style, $parentBlock); |
||
| 254 | $tableWrapper->appendTableBox($childDomElement, $element, $style, $parentBlock); |
||
| 255 | |||
| 256 | break; |
||
| 257 | case 'table-row-group': |
||
| 258 | case 'table-header-group': |
||
| 259 | case 'table-footer-group': |
||
| 260 | $this->appendTableRowGroupBox($childDomElement, $element, $style, $parentBlock, $display); |
||
| 261 | |||
| 262 | break; |
||
| 263 | case 'table-row': |
||
| 264 | $this->appendTableRowBox($childDomElement, $element, $style, $parentBlock); |
||
| 265 | |||
| 266 | break; |
||
| 267 | case 'table-cell': |
||
| 268 | $this->appendTableCellBox($childDomElement, $element, $style, $parentBlock); |
||
| 269 | |||
| 270 | break; |
||
| 271 | case 'inline': |
||
| 272 | $inline = $this->appendInlineBox($childDomElement, $element, $style, $parentBlock); |
||
| 273 | if (isset($inline) && $childDomElement instanceof \DOMText) { |
||
| 274 | $inline->setAnonymous(true)->appendText($childDomElement, null, null, $parentBlock); |
||
| 275 | } |
||
| 276 | |||
| 277 | break; |
||
| 278 | case 'inline-block': |
||
| 279 | $this->appendInlineBlockBox($childDomElement, $element, $style, $parentBlock); |
||
| 280 | |||
| 281 | break; |
||
| 282 | case 'none': |
||
| 283 | if ('style' === $childDomElement->nodeName) { |
||
| 284 | $this->appendStyleBox($childDomElement, $element, $style, $parentBlock); |
||
| 285 | } |
||
| 286 | |||
| 287 | break; |
||
| 288 | } |
||
| 289 | } |
||
| 290 | } |
||
| 291 | |||
| 292 | return $this; |
||
| 293 | } |
||
| 295 |