| Conditions | 10 |
| Paths | 30 |
| Total Lines | 33 |
| 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 |
||
| 82 | public function render($type = 'html') |
||
| 83 | { |
||
| 84 | $row = $this->getTable()->getRow()->getActualRow(); |
||
| 85 | |||
| 86 | $value = ''; |
||
| 87 | |||
| 88 | if (is_array($row) || $row instanceof \ArrayAccess) { |
||
| 89 | $value = (isset($row[$this->getHeader()->getName()])) ? $row[$this->getHeader()->getName()] : ''; |
||
| 90 | } elseif (is_object($row)) { |
||
| 91 | $headerName = $this->getHeader()->getName(); |
||
| 92 | $methodName = 'get' . ucfirst($headerName); |
||
| 93 | if (method_exists($row, $methodName)) { |
||
| 94 | $value = $row->$methodName(); |
||
| 95 | } else { |
||
| 96 | $value = (property_exists($row, $headerName)) ? $row->$headerName : ''; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | foreach ($this->decorators as $decorator) { |
||
| 101 | if ($decorator->validConditions()) { |
||
| 102 | $value = $decorator->render($value); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | if ($type == 'html') { |
||
| 107 | $ret = sprintf("<td %s>%s</td>", $this->getAttributes(), $value); |
||
| 108 | $this->clearVar(); |
||
| 109 | return $ret; |
||
| 110 | |||
| 111 | } else { |
||
| 112 | return $value; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 |