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