Conditions | 12 |
Paths | 99 |
Total Lines | 47 |
Code Lines | 23 |
Lines | 16 |
Ratio | 34.04 % |
Changes | 6 | ||
Bugs | 0 | Features | 4 |
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 |
||
87 | public function render(Row $row) |
||
88 | { |
||
89 | /** |
||
90 | * Disable function may be used (user may not have permission to see this action) |
||
91 | */ |
||
92 | if ($this->disable_callback && call_user_func_array($this->disable_callback, [$row->getItem()])) { |
||
93 | return; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Renderer function may be used |
||
98 | */ |
||
99 | View Code Duplication | if ($renderer = $this->getRenderer()) { |
|
|
|||
100 | if (!$renderer->getConditionCallback()) { |
||
101 | return call_user_func_array($renderer->getCallback(), [$row->getItem()]); |
||
102 | } |
||
103 | |||
104 | if (call_user_func_array($this->getRenderer(), [$row->getItem()])) { |
||
105 | return call_user_func_array($renderer->getCallback(), [$row->getItem()]); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | try { |
||
110 | $parent = $this->grid->getParent(); |
||
111 | } catch (DataGridHasToBeAttachedToPresenterComponentException $e) { |
||
112 | $parent = $this->grid->getPresenter(); |
||
113 | } |
||
114 | |||
115 | $a = Html::el('a') |
||
116 | ->href($parent->link($this->href, $this->getItemParams($row))); |
||
117 | |||
118 | View Code Duplication | if ($this->icon) { |
|
119 | $a->add(Html::el('span')->class(DataGrid::$icon_prefix.$this->icon)); |
||
120 | |||
121 | if (strlen($this->name)) { |
||
122 | $a->add(' '); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | $a->add($this->name); |
||
127 | |||
128 | if ($this->title) { $a->title($this->title); } |
||
129 | if ($this->class) { $a->class($this->class); } |
||
130 | if ($confirm = $this->getConfirm($row)) { $a->data('confirm', $confirm); } |
||
131 | |||
132 | return $a; |
||
133 | } |
||
134 | |||
280 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.