| Conditions | 4 |
| Paths | 4 |
| Total Lines | 59 |
| Code Lines | 35 |
| 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 |
||
| 96 | function performVisibleFoldersHtmlUpdate( |
||
| 97 | int $user_id, |
||
| 98 | array $SETTINGS |
||
|
|
|||
| 99 | ) |
||
| 100 | { |
||
| 101 | $html = []; |
||
| 102 | |||
| 103 | // rebuild tree |
||
| 104 | require_once __DIR__. '/../sources/SplClassLoader.php'; |
||
| 105 | require_once __DIR__. '/../includes/libraries/Tree/NestedTree/NestedTree.php'; |
||
| 106 | $tree = new Tree\NestedTree\NestedTree(prefixTable('nested_tree'), 'id', 'parent_id', 'title'); |
||
| 107 | $tree->rebuild(); |
||
| 108 | |||
| 109 | // get current folders visible for user |
||
| 110 | $cache_tree = DB::queryFirstRow( |
||
| 111 | 'SELECT increment_id, data FROM ' . prefixTable('cache_tree') . ' WHERE user_id = %i', |
||
| 112 | $user_id |
||
| 113 | ); |
||
| 114 | $folders = json_decode($cache_tree['data'], true);//print_r($folders); |
||
| 115 | foreach ($folders as $folder) { |
||
| 116 | $idFolder = (int) explode("li_", $folder['id'])[1]; |
||
| 117 | |||
| 118 | // Get path |
||
| 119 | $path = ''; |
||
| 120 | $tree_path = $tree->getPath($idFolder, false); |
||
| 121 | foreach ($tree_path as $fld) { |
||
| 122 | $path .= empty($path) === true ? $fld->title : '/'.$fld->title; |
||
| 123 | } |
||
| 124 | |||
| 125 | // get folder info |
||
| 126 | $folder = DB::queryFirstRow( |
||
| 127 | 'SELECT title, parent_id, personal_folder FROM ' . prefixTable('nested_tree') . ' WHERE id = %i', |
||
| 128 | $idFolder |
||
| 129 | ); |
||
| 130 | |||
| 131 | // finalize |
||
| 132 | array_push( |
||
| 133 | $html, |
||
| 134 | [ |
||
| 135 | "path" => $path, |
||
| 136 | "id" => $idFolder, |
||
| 137 | "level" => count($tree_path), |
||
| 138 | "title" => $folder['title'], |
||
| 139 | "disabled" => 0, |
||
| 140 | "parent_id" => $folder['parent_id'], |
||
| 141 | "perso" => $folder['personal_folder'], |
||
| 142 | "is_visible_active" => 1, |
||
| 143 | ] |
||
| 144 | ); |
||
| 145 | } |
||
| 146 | |||
| 147 | DB::update( |
||
| 148 | prefixTable('cache_tree'), |
||
| 149 | array( |
||
| 150 | 'visible_folders' => json_encode($html), |
||
| 151 | 'timestamp' => time(), |
||
| 152 | ), |
||
| 153 | 'increment_id = %i', |
||
| 154 | (int) $cache_tree['increment_id'] |
||
| 155 | ); |
||
| 156 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.