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