| Conditions | 1 |
| Paths | 1 |
| Total Lines | 115 |
| 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 |
||
| 189 | private function registerScriptTreeViewActionsDragAndDrop() |
||
| 190 | {
|
||
| 191 | $treeId = 'tree_'.get_class($this->model); |
||
| 192 | $dragAndDropUrl = Yii::app()->controller->createUrl('info/dragAndDrop');
|
||
| 193 | |||
| 194 | Yii::app()->clientScript->registerScript(__CLASS__.'_dragAndDrop', " |
||
| 195 | var treeId = '{$treeId}';
|
||
| 196 | |||
| 197 | var dragAndDropUrl = '{$dragAndDropUrl}';
|
||
| 198 | var parentSelector; |
||
| 199 | var targetSelector; |
||
| 200 | |||
| 201 | $('ul.filetree').on('click', 'li#node_1>a', function(e){
|
||
| 202 | e.preventDefault(); |
||
| 203 | }); |
||
| 204 | |||
| 205 | var dropCallback = function(target, draggableItem) |
||
| 206 | {
|
||
| 207 | var callback = function callback(resp) |
||
| 208 | {
|
||
| 209 | if( $(resp).attr('id') == treeId )
|
||
| 210 | {
|
||
| 211 | $('#sidebar').find('#'+treeId).html($(resp).html());
|
||
| 212 | $('#' + treeId).treeview({'persist':'cookie', 'collapsed':true, 'animated':'fast'});
|
||
| 213 | initTreeDragAndDrop($('#' + treeId));
|
||
| 214 | initTreeActions(); |
||
| 215 | } |
||
| 216 | } |
||
| 217 | |||
| 218 | var draggableText = draggableItem.children('a').text()
|
||
| 219 | var targetText = target.children('a').text()
|
||
| 220 | var current = $('#' + treeId + ' li.current').length > 0 ? $('#' + treeId + ' li.current').attr('id').match(/node_(\d+)/)[1] : 0
|
||
| 221 | |||
| 222 | var dragId = draggableItem.attr('id').match(/node_(\d+)/)[1];
|
||
| 223 | var dropId = target.attr('id').match(/node_(\d+)/)[1];
|
||
| 224 | var parentDragId = parentSelector.attr('id').match(/node_(\d+)/)[1];
|
||
| 225 | |||
| 226 | draggableItem.height('auto');
|
||
| 227 | |||
| 228 | if( parentDragId == dropId ) |
||
| 229 | return false; |
||
| 230 | |||
| 231 | if( confirm('Вы действительно хотите перенести раздел \"' + draggableText + '\" в \"' + targetText + '\"' ) )
|
||
| 232 | {
|
||
| 233 | $.post(dragAndDropUrl, {
|
||
| 234 | 'action' : 'move', |
||
| 235 | 'drag' : dragId, |
||
| 236 | 'drop' : dropId, |
||
| 237 | 'current' : current |
||
| 238 | } |
||
| 239 | , callback); |
||
| 240 | |||
| 241 | return true; |
||
| 242 | } |
||
| 243 | else |
||
| 244 | return false; |
||
| 245 | }; |
||
| 246 | |||
| 247 | var initTreeDragAndDrop = function(tree) |
||
| 248 | {
|
||
| 249 | var treeItems = tree.find('li');
|
||
| 250 | |||
| 251 | $(treeItems).droppable({
|
||
| 252 | tolerance : 'pointer', |
||
| 253 | hoverClass: 'drop-hover', |
||
| 254 | greedy: true, |
||
| 255 | drop: function() {
|
||
| 256 | targetSelector = $(this); |
||
| 257 | } |
||
| 258 | }); |
||
| 259 | |||
| 260 | $(treeItems).draggable({
|
||
| 261 | connectToSortable: '#' + tree.attr('id'),
|
||
| 262 | revert: true, |
||
| 263 | revertDuration: 0, |
||
| 264 | draggableItem: null, |
||
| 265 | start: function() {
|
||
| 266 | this.draggableItem = $(this); |
||
| 267 | parentSelector = $(this).parent().parent(); |
||
| 268 | targetSelector = null; |
||
| 269 | }, |
||
| 270 | stop: function() |
||
| 271 | {
|
||
| 272 | if( targetSelector && !dropCallback(targetSelector, this.draggableItem) ) |
||
| 273 | return; |
||
| 274 | |||
| 275 | if ( targetSelector !== null ) |
||
| 276 | {
|
||
| 277 | if ( targetSelector.hasClass('folder') )
|
||
| 278 | {
|
||
| 279 | $(this).appendTo(targetSelector.children('ul'));
|
||
| 280 | } |
||
| 281 | else |
||
| 282 | {
|
||
| 283 | var htmlContent = '<div class=\"hitarea folder-hitarea collapsable-hitarea\"></div>'+ targetSelector.html() +'<ul style=\"display: block;\"></ul>'; |
||
| 284 | targetSelector.removeClass('file').addClass('folder collapsable').html(htmlContent);
|
||
| 285 | $(this).appendTo(targetSelector.children('ul'));
|
||
| 286 | } |
||
| 287 | } |
||
| 288 | else |
||
| 289 | $(this).appendTo(tree); |
||
| 290 | |||
| 291 | if( !parentSelector.children('ul').has('li').length )
|
||
| 292 | {
|
||
| 293 | parentSelector.removeClass('folder')
|
||
| 294 | .addClass('file')
|
||
| 295 | .html('<a href=\"'+ parentSelector.children('a').attr('href') +'\">' + parentSelector.children('a').html() + '</a>');
|
||
| 296 | } |
||
| 297 | } |
||
| 298 | }); |
||
| 299 | }; |
||
| 300 | |||
| 301 | initTreeDragAndDrop($('#' + treeId));
|
||
| 302 | ", CClientScript::POS_READY); |
||
| 303 | } |
||
| 304 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.