| Conditions | 37 |
| Paths | 8082 |
| Total Lines | 154 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 55 | public function render(Frame $frame) |
||
| 56 | { |
||
| 57 | global $_dompdf_debug; |
||
| 58 | |||
| 59 | $this->_check_callbacks("begin_frame", $frame); |
||
| 60 | |||
| 61 | if ($_dompdf_debug) { |
||
| 62 | echo $frame; |
||
| 63 | flush(); |
||
| 64 | } |
||
| 65 | |||
| 66 | $style = $frame->get_style(); |
||
| 67 | |||
| 68 | if (in_array($style->visibility, array("hidden", "collapse"))) { |
||
| 69 | return; |
||
| 70 | } |
||
| 71 | |||
| 72 | $display = $style->display; |
||
| 73 | |||
| 74 | // Starts the CSS transformation |
||
| 75 | if ($style->transform && is_array($style->transform)) { |
||
| 76 | $this->_canvas->save(); |
||
| 77 | list($x, $y) = $frame->get_padding_box(); |
||
| 78 | $origin = $style->transform_origin; |
||
| 79 | |||
| 80 | foreach ($style->transform as $transform) { |
||
| 81 | list($function, $values) = $transform; |
||
| 82 | if ($function === "matrix") { |
||
| 83 | $function = "transform"; |
||
| 84 | } |
||
| 85 | |||
| 86 | $values = array_map("floatval", $values); |
||
| 87 | $values[] = $x + (float)$style->length_in_pt($origin[0], (float)$style->length_in_pt($style->width)); |
||
| 88 | $values[] = $y + (float)$style->length_in_pt($origin[1], (float)$style->length_in_pt($style->height)); |
||
| 89 | |||
| 90 | call_user_func_array(array($this->_canvas, $function), $values); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | switch ($display) { |
||
| 95 | |||
| 96 | case "block": |
||
| 97 | case "list-item": |
||
| 98 | case "inline-block": |
||
| 99 | case "table": |
||
| 100 | case "inline-table": |
||
| 101 | $this->_render_frame("block", $frame); |
||
| 102 | break; |
||
| 103 | |||
| 104 | case "inline": |
||
| 105 | if ($frame->is_text_node()) { |
||
| 106 | $this->_render_frame("text", $frame); |
||
| 107 | } else { |
||
| 108 | $this->_render_frame("inline", $frame); |
||
| 109 | } |
||
| 110 | break; |
||
| 111 | |||
| 112 | case "table-cell": |
||
| 113 | $this->_render_frame("table-cell", $frame); |
||
| 114 | break; |
||
| 115 | |||
| 116 | case "table-row-group": |
||
| 117 | case "table-header-group": |
||
| 118 | case "table-footer-group": |
||
| 119 | $this->_render_frame("table-row-group", $frame); |
||
| 120 | break; |
||
| 121 | |||
| 122 | case "-dompdf-list-bullet": |
||
| 123 | $this->_render_frame("list-bullet", $frame); |
||
| 124 | break; |
||
| 125 | |||
| 126 | case "-dompdf-image": |
||
| 127 | $this->_render_frame("image", $frame); |
||
| 128 | break; |
||
| 129 | |||
| 130 | case "none": |
||
| 131 | $node = $frame->get_node(); |
||
| 132 | |||
| 133 | if ($node->nodeName === "script") { |
||
| 134 | if ($node->getAttribute("type") === "text/php" || |
||
| 135 | $node->getAttribute("language") === "php" |
||
| 136 | ) { |
||
| 137 | // Evaluate embedded php scripts |
||
| 138 | $this->_render_frame("php", $frame); |
||
| 139 | } elseif ($node->getAttribute("type") === "text/javascript" || |
||
| 140 | $node->getAttribute("language") === "javascript" |
||
| 141 | ) { |
||
| 142 | // Insert JavaScript |
||
| 143 | $this->_render_frame("javascript", $frame); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | // Don't render children, so skip to next iter |
||
| 148 | return; |
||
| 149 | |||
| 150 | default: |
||
| 151 | break; |
||
| 152 | |||
| 153 | } |
||
| 154 | |||
| 155 | // Starts the overflow: hidden box |
||
| 156 | if ($style->overflow === "hidden") { |
||
| 157 | list($x, $y, $w, $h) = $frame->get_padding_box(); |
||
| 158 | |||
| 159 | // get border radii |
||
| 160 | $style = $frame->get_style(); |
||
| 161 | list($tl, $tr, $br, $bl) = $style->get_computed_border_radius($w, $h); |
||
| 162 | |||
| 163 | if ($tl + $tr + $br + $bl > 0) { |
||
| 164 | $this->_canvas->clipping_roundrectangle($x, $y, (float)$w, (float)$h, $tl, $tr, $br, $bl); |
||
| 165 | } else { |
||
| 166 | $this->_canvas->clipping_rectangle($x, $y, (float)$w, (float)$h); |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | $stack = array(); |
||
| 171 | |||
| 172 | foreach ($frame->get_children() as $child) { |
||
| 173 | // < 0 : nagative z-index |
||
| 174 | // = 0 : no z-index, no stacking context |
||
| 175 | // = 1 : stacking context without z-index |
||
| 176 | // > 1 : z-index |
||
| 177 | $child_style = $child->get_style(); |
||
| 178 | $child_z_index = $child_style->z_index; |
||
| 179 | $z_index = 0; |
||
| 180 | |||
| 181 | if ($child_z_index !== "auto") { |
||
| 182 | $z_index = intval($child_z_index) + 1; |
||
| 183 | } elseif ($child_style->float !== "none" || $child->is_positionned()) { |
||
| 184 | $z_index = 1; |
||
| 185 | } |
||
| 186 | |||
| 187 | $stack[$z_index][] = $child; |
||
| 188 | } |
||
| 189 | |||
| 190 | ksort($stack); |
||
| 191 | |||
| 192 | foreach ($stack as $by_index) { |
||
| 193 | foreach ($by_index as $child) { |
||
| 194 | $this->render($child); |
||
| 195 | } |
||
| 196 | } |
||
| 197 | |||
| 198 | // Ends the overflow: hidden box |
||
| 199 | if ($style->overflow === "hidden") { |
||
| 200 | $this->_canvas->clipping_end(); |
||
| 201 | } |
||
| 202 | |||
| 203 | if ($style->transform && is_array($style->transform)) { |
||
| 204 | $this->_canvas->restore(); |
||
| 205 | } |
||
| 206 | |||
| 207 | // Check for end frame callback |
||
| 208 | $this->_check_callbacks("end_frame", $frame); |
||
| 209 | } |
||
| 296 |