| Conditions | 9 |
| Paths | 8 |
| Total Lines | 75 |
| Code Lines | 49 |
| 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 |
||
| 43 | public function getItems(string $sqlExtra, int $limit, string $userPrivateKey, int $userId): array |
||
| 44 | { |
||
| 45 | $rows = $this->select( |
||
| 46 | "SELECT i.id, label, description, i.pw, i.url, i.id_tree, i.login, i.email, i.viewed_no, i.fa_icon, i.inactif, i.perso, t.title as folder_label |
||
| 47 | FROM ".prefixTable('items')." as i |
||
| 48 | LEFT JOIN ".prefixTable('nested_tree')." as t ON (t.id = i.id_tree) ". |
||
| 49 | $sqlExtra . |
||
| 50 | " ORDER BY i.id ASC" . |
||
| 51 | //($limit > 0 ? " LIMIT ?". ["i", $limit] : '') |
||
| 52 | ($limit > 0 ? " LIMIT ". $limit : '') |
||
| 53 | ); |
||
| 54 | $ret = []; |
||
| 55 | foreach ($rows as $row) { |
||
| 56 | $userKey = $this->select( |
||
| 57 | 'SELECT share_key |
||
| 58 | FROM ' . prefixTable('sharekeys_items') . ' |
||
| 59 | WHERE user_id = '.$userId.' AND object_id = '.$row['id'] |
||
| 60 | ); |
||
| 61 | if (count($userKey) === 0 || empty($row['pw']) === true) { |
||
| 62 | // No share key found |
||
| 63 | // Exit this item |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | |||
| 67 | // Get password |
||
| 68 | try { |
||
| 69 | $pwd = base64_decode( |
||
| 70 | (string) doDataDecryption( |
||
| 71 | $row['pw'], |
||
| 72 | decryptUserObjectKey( |
||
| 73 | $userKey[0]['share_key'], |
||
| 74 | $userPrivateKey |
||
| 75 | ) |
||
| 76 | ) |
||
| 77 | ); |
||
| 78 | } catch (Exception $e) { |
||
| 79 | // Password is not encrypted |
||
| 80 | echo "ERROR"; |
||
| 81 | } |
||
| 82 | |||
| 83 | |||
| 84 | // get path to item |
||
| 85 | $tree = new NestedTree(prefixTable('nested_tree'), 'id', 'parent_id', 'title'); |
||
| 86 | $arbo = $tree->getPath($row['id_tree'], false); |
||
| 87 | $path = ''; |
||
| 88 | foreach ($arbo as $elem) { |
||
| 89 | if (empty($path) === true) { |
||
| 90 | $path = htmlspecialchars(stripslashes(htmlspecialchars_decode($elem->title, ENT_QUOTES)), ENT_QUOTES); |
||
| 91 | } else { |
||
| 92 | $path .= '/' . htmlspecialchars(stripslashes(htmlspecialchars_decode($elem->title, ENT_QUOTES)), ENT_QUOTES); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | array_push( |
||
| 97 | $ret, |
||
| 98 | [ |
||
| 99 | 'id' => (int) $row['id'], |
||
| 100 | 'label' => $row['label'], |
||
| 101 | 'description' => $row['description'], |
||
| 102 | 'pwd' => $pwd, |
||
| 103 | 'url' => $row['url'], |
||
| 104 | 'login' => $row['login'], |
||
| 105 | 'email' => $row['email'], |
||
| 106 | 'viewed_no' => (int) $row['viewed_no'], |
||
| 107 | 'fa_icon' => $row['fa_icon'], |
||
| 108 | 'inactif' => (int) $row['inactif'], |
||
| 109 | 'perso' => (int) $row['perso'], |
||
| 110 | 'id_tree' => (int) $row['id_tree'], |
||
| 111 | 'folder_label' => $row['folder_label'], |
||
| 112 | 'path' => empty($path) === true ? '' : $path, |
||
| 113 | ] |
||
| 114 | ); |
||
| 115 | } |
||
| 116 | |||
| 117 | return $ret; |
||
| 118 | } |
||
| 132 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.