| Conditions | 24 |
| Paths | 964 |
| Total Lines | 96 |
| Code Lines | 66 |
| 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 |
||
| 36 | public function renderTab(Representation $r) |
||
| 37 | { |
||
| 38 | $out = '<pre><table><thead><tr><th></th>'; |
||
| 39 | |||
| 40 | $firstrow = \reset($r->contents); |
||
| 41 | |||
| 42 | foreach ($firstrow->value->contents as $field) { |
||
| 43 | $out .= '<th>'.$this->renderer->escape($field->name).'</th>'; |
||
| 44 | } |
||
| 45 | |||
| 46 | $out .= '</tr></thead><tbody>'; |
||
| 47 | |||
| 48 | foreach ($r->contents as $row) { |
||
| 49 | $out .= '<tr><th>'; |
||
| 50 | $out .= $this->renderer->escape($row->name); |
||
| 51 | $out .= '</th>'; |
||
| 52 | |||
| 53 | foreach ($row->value->contents as $field) { |
||
| 54 | $out .= '<td'; |
||
| 55 | $type = ''; |
||
| 56 | $size = ''; |
||
| 57 | $ref = ''; |
||
| 58 | |||
| 59 | if (null !== ($s = $field->getType())) { |
||
| 60 | $type = $this->renderer->escape($s); |
||
| 61 | |||
| 62 | if ($field->reference) { |
||
| 63 | $ref = '&'; |
||
| 64 | $type = $ref.$type; |
||
| 65 | } |
||
| 66 | |||
| 67 | if (null !== ($s = $field->getSize())) { |
||
| 68 | $size .= ' ('.$this->renderer->escape($s).')'; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | if ($type) { |
||
| 73 | $out .= ' title="'.$type.$size.'"'; |
||
| 74 | } |
||
| 75 | |||
| 76 | $out .= '>'; |
||
| 77 | |||
| 78 | switch ($field->type) { |
||
| 79 | case 'boolean': |
||
| 80 | $out .= $field->value->contents ? '<var>'.$ref.'true</var>' : '<var>'.$ref.'false</var>'; |
||
| 81 | break; |
||
| 82 | case 'integer': |
||
| 83 | case 'double': |
||
| 84 | $out .= (string) $field->value->contents; |
||
| 85 | break; |
||
| 86 | case 'null': |
||
| 87 | $out .= '<var>'.$ref.'null</var>'; |
||
| 88 | break; |
||
| 89 | case 'string': |
||
| 90 | if ($field->encoding) { |
||
| 91 | $val = $field->value->contents; |
||
| 92 | if (RichRenderer::$strlen_max && self::$respect_str_length && BlobObject::strlen($val) > RichRenderer::$strlen_max) { |
||
| 93 | $val = \substr($val, 0, RichRenderer::$strlen_max).'...'; |
||
| 94 | } |
||
| 95 | |||
| 96 | $out .= $this->renderer->escape($val); |
||
| 97 | } else { |
||
| 98 | $out .= '<var>'.$type.'</var>'; |
||
| 99 | } |
||
| 100 | break; |
||
| 101 | case 'array': |
||
| 102 | $out .= '<var>'.$ref.'array</var>'.$size; |
||
| 103 | break; |
||
| 104 | case 'object': |
||
| 105 | $out .= '<var>'.$ref.$this->renderer->escape($field->classname).'</var>'.$size; |
||
| 106 | break; |
||
| 107 | case 'resource': |
||
| 108 | $out .= '<var>'.$ref.'resource</var>'; |
||
| 109 | break; |
||
| 110 | default: |
||
| 111 | $out .= '<var>'.$ref.'unknown</var>'; |
||
| 112 | break; |
||
| 113 | } |
||
| 114 | |||
| 115 | if (\in_array('blacklist', $field->hints, true)) { |
||
| 116 | $out .= ' <var>Blacklisted</var>'; |
||
| 117 | } elseif (\in_array('recursion', $field->hints, true)) { |
||
| 118 | $out .= ' <var>Recursion</var>'; |
||
| 119 | } elseif (\in_array('depth_limit', $field->hints, true)) { |
||
| 120 | $out .= ' <var>Depth Limit</var>'; |
||
| 121 | } |
||
| 122 | |||
| 123 | $out .= '</td>'; |
||
| 124 | } |
||
| 125 | |||
| 126 | $out .= '</tr>'; |
||
| 127 | } |
||
| 128 | |||
| 129 | $out .= '</tbody></table></pre>'; |
||
| 130 | |||
| 131 | return $out; |
||
| 132 | } |
||
| 134 |