| Conditions | 10 |
| Paths | 18 |
| Total Lines | 44 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 50 | public function read($pref_name, $user_id = false, $die_on_error = false) { |
||
| 51 | |||
| 52 | if (!$user_id) { |
||
| 53 | $user_id = $_SESSION["uid"]; |
||
| 54 | @$profile = $_SESSION["profile"]; |
||
| 55 | } else { |
||
| 56 | $profile = false; |
||
| 57 | } |
||
| 58 | |||
| 59 | if ($user_id == $_SESSION['uid'] && isset($this->cache[$pref_name])) { |
||
| 60 | $tuple = $this->cache[$pref_name]; |
||
| 61 | return $this->convert($tuple["value"], $tuple["type"]); |
||
| 62 | } |
||
| 63 | |||
| 64 | if (!is_numeric($profile) || !$profile || get_schema_version() < 63) $profile = null; |
||
| 65 | |||
| 66 | $sth = $this->pdo->prepare("SELECT |
||
| 67 | value,ttrss_prefs_types.type_name as type_name |
||
| 68 | FROM |
||
| 69 | ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types |
||
| 70 | WHERE |
||
| 71 | (profile = :profile OR (:profile IS NULL AND profile IS NULL)) AND |
||
| 72 | ttrss_user_prefs.pref_name = :pref_name AND |
||
| 73 | ttrss_prefs_types.id = type_id AND |
||
| 74 | owner_uid = :uid AND |
||
| 75 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name"); |
||
| 76 | $sth->execute([":uid" => $user_id, ":profile" => $profile, ":pref_name" => $pref_name]); |
||
| 77 | |||
| 78 | if ($row = $sth->fetch()) { |
||
| 79 | $value = $row["value"]; |
||
| 80 | $type_name = $row["type_name"]; |
||
| 81 | |||
| 82 | if ($user_id == $_SESSION["uid"]) { |
||
| 83 | $this->cache[$pref_name]["type"] = $type_name; |
||
| 84 | $this->cache[$pref_name]["value"] = $value; |
||
| 85 | } |
||
| 86 | |||
| 87 | return $this->convert($value, $type_name); |
||
| 88 | |||
| 89 | } else if ($die_on_error) { |
||
| 90 | user_error("Fatal error, unknown preferences key: $pref_name (owner: $user_id)", E_USER_ERROR); |
||
| 91 | return null; |
||
| 92 | } else { |
||
| 93 | return null; |
||
| 94 | } |
||
| 169 |