| Conditions | 12 |
| Paths | 98 |
| Total Lines | 57 |
| Code Lines | 29 |
| 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 |
||
| 84 | public function render(Row $row) |
||
| 85 | { |
||
| 86 | /** |
||
| 87 | * Renderer function may be used |
||
| 88 | */ |
||
| 89 | try { |
||
| 90 | return $this->useRenderer($row); |
||
| 91 | } catch (DataGridColumnRendererException $e) { |
||
|
|
|||
| 92 | /** |
||
| 93 | * Do not use renderer |
||
| 94 | */ |
||
| 95 | } |
||
| 96 | |||
| 97 | $value = parent::render($row); |
||
| 98 | |||
| 99 | if (!$value && !$this->icon) { |
||
| 100 | return NULL; |
||
| 101 | } |
||
| 102 | |||
| 103 | $a = Html::el('a') |
||
| 104 | ->href($this->createLink( |
||
| 105 | $this->grid, |
||
| 106 | $this->href, |
||
| 107 | $this->getItemParams($row, $this->params) + $this->parameters |
||
| 108 | )); |
||
| 109 | |||
| 110 | if (!empty($this->data_attributes)) { |
||
| 111 | foreach ($this->data_attributes as $key => $attr_value) { |
||
| 112 | $a->data($key, $attr_value); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | if ($this->open_in_new_tab) { |
||
| 117 | $a->addAttributes(['target' => '_blank']); |
||
| 118 | } |
||
| 119 | |||
| 120 | if ($this->title) { $a->title($this->title); } |
||
| 121 | if ($this->class) { $a->class($this->class); } |
||
| 122 | |||
| 123 | $element = $a; |
||
| 124 | |||
| 125 | if ($this->icon) { |
||
| 126 | $a->addHtml(Html::el('span')->class(DataGrid::$icon_prefix . $this->icon)); |
||
| 127 | |||
| 128 | if (strlen($value)) { |
||
| 129 | $a->addHtml(' '); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | if ($this->isTemplateEscaped()) { |
||
| 134 | $a->addText($value); |
||
| 135 | } else { |
||
| 136 | $a->addHtml($value); |
||
| 137 | } |
||
| 138 | |||
| 139 | return $element; |
||
| 140 | } |
||
| 141 | |||
| 246 |