| Conditions | 1 |
| Paths | 1 |
| Total Lines | 65 |
| 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 |
||
| 97 | protected function addScript() |
||
| 98 | { |
||
| 99 | $rowName = $this->grid->getGridRowName(); |
||
| 100 | |||
| 101 | $script = <<<SCRIPT |
||
| 102 | |||
| 103 | (function () { |
||
| 104 | var theadHeight = $('.table-main thead tr').outerHeight(); |
||
| 105 | $('.table-fixed thead tr').outerHeight(theadHeight); |
||
| 106 | |||
| 107 | var tfootHeight = $('.table-main tfoot tr').outerHeight(); |
||
| 108 | $('.table-fixed tfoot tr').outerHeight(tfootHeight); |
||
| 109 | |||
| 110 | $('.table-main tbody tr').each(function(i, obj) { |
||
| 111 | var height = $(obj).outerHeight(); |
||
| 112 | |||
| 113 | $('.table-fixed-left tbody tr').eq(i).outerHeight(height); |
||
| 114 | $('.table-fixed-right tbody tr').eq(i).outerHeight(height); |
||
| 115 | }); |
||
| 116 | |||
| 117 | if ($('.table-main').width() >= $('.table-main').prop('scrollWidth')) { |
||
| 118 | $('.table-fixed').hide(); |
||
| 119 | } |
||
| 120 | |||
| 121 | $('.table-wrap tbody tr').on('mouseover', function () { |
||
| 122 | var index = $(this).index(); |
||
| 123 | |||
| 124 | $('.table-main tbody tr').eq(index).addClass('active'); |
||
| 125 | $('.table-fixed-left tbody tr').eq(index).addClass('active'); |
||
| 126 | $('.table-fixed-right tbody tr').eq(index).addClass('active'); |
||
| 127 | }); |
||
| 128 | |||
| 129 | $('.table-wrap tbody tr').on('mouseout', function () { |
||
| 130 | var index = $(this).index(); |
||
| 131 | |||
| 132 | $('.table-main tbody tr').eq(index).removeClass('active'); |
||
| 133 | $('.table-fixed-left tbody tr').eq(index).removeClass('active'); |
||
| 134 | $('.table-fixed-right tbody tr').eq(index).removeClass('active'); |
||
| 135 | }); |
||
| 136 | |||
| 137 | $('.{$rowName}-checkbox').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChanged', function () { |
||
| 138 | |||
| 139 | var id = $(this).data('id'); |
||
| 140 | var index = $(this).closest('tr').index(); |
||
| 141 | |||
| 142 | if (this.checked) { |
||
| 143 | \$.admin.grid.select(id); |
||
| 144 | $('.table-main tbody tr').eq(index).css('background-color', '#ffffd5'); |
||
| 145 | $('.table-fixed-left tbody tr').eq(index).css('background-color', '#ffffd5'); |
||
| 146 | $('.table-fixed-right tbody tr').eq(index).css('background-color', '#ffffd5'); |
||
| 147 | } else { |
||
| 148 | \$.admin.grid.unselect(id); |
||
| 149 | $('.table-main tbody tr').eq(index).css('background-color', ''); |
||
| 150 | $('.table-fixed-left tbody tr').eq(index).css('background-color', ''); |
||
| 151 | $('.table-fixed-right tbody tr').eq(index).css('background-color', ''); |
||
| 152 | } |
||
| 153 | }); |
||
| 154 | })(); |
||
| 155 | |||
| 156 | SCRIPT; |
||
| 157 | |||
| 158 | Admin::script($script); |
||
| 159 | |||
| 160 | return $this; |
||
| 161 | } |
||
| 162 | |||
| 212 | } |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: