Conditions | 18 |
Paths | 832 |
Total Lines | 63 |
Code Lines | 36 |
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 |
||
114 | public function write($pref_name, $value, $user_id = false, $strip_tags = true) { |
||
115 | if ($strip_tags) { |
||
116 | $value = strip_tags($value); |
||
117 | } |
||
118 | |||
119 | if (!$user_id) { |
||
120 | $user_id = $_SESSION["uid"]; |
||
121 | @$profile = $_SESSION["profile"]; |
||
122 | } else { |
||
123 | $profile = null; |
||
124 | } |
||
125 | |||
126 | if (!is_numeric($profile) || !$profile || get_schema_version() < 63) { |
||
127 | $profile = null; |
||
128 | } |
||
129 | |||
130 | $type_name = ""; |
||
131 | $current_value = ""; |
||
132 | |||
133 | if (isset($this->cache[$pref_name])) { |
||
134 | $type_name = $this->cache[$pref_name]["type"]; |
||
135 | $current_value = $this->cache[$pref_name]["value"]; |
||
136 | } |
||
137 | |||
138 | if (!$type_name) { |
||
139 | $sth = $this->pdo->prepare("SELECT type_name |
||
140 | FROM ttrss_prefs,ttrss_prefs_types |
||
141 | WHERE pref_name = ? AND type_id = ttrss_prefs_types.id"); |
||
142 | $sth->execute([$pref_name]); |
||
143 | |||
144 | if ($row = $sth->fetch()) { |
||
145 | $type_name = $row["type_name"]; |
||
146 | } |
||
147 | |||
148 | } else if ($current_value == $value) { |
||
149 | return; |
||
150 | } |
||
151 | |||
152 | if ($type_name) { |
||
153 | if ($type_name == "bool") { |
||
154 | if ($value == "1" || $value == "true") { |
||
155 | $value = "true"; |
||
156 | } else { |
||
157 | $value = "false"; |
||
158 | } |
||
159 | } else if ($type_name == "integer") { |
||
160 | $value = (int) $value; |
||
161 | } |
||
162 | |||
163 | if ($pref_name == 'USER_TIMEZONE' && $value == '') { |
||
164 | $value = 'UTC'; |
||
165 | } |
||
166 | |||
167 | $sth = $this->pdo->prepare("UPDATE ttrss_user_prefs SET |
||
168 | value = :value WHERE pref_name = :pref_name |
||
169 | AND (profile = :profile OR (:profile IS NULL AND profile IS NULL)) |
||
170 | AND owner_uid = :uid"); |
||
171 | |||
172 | $sth->execute([":pref_name" => $pref_name, ":value" => $value, ":uid" => $user_id, ":profile" => $profile]); |
||
173 | |||
174 | if ($user_id == $_SESSION["uid"]) { |
||
175 | $this->cache[$pref_name]["type"] = $type_name; |
||
176 | $this->cache[$pref_name]["value"] = $value; |
||
177 | } |
||
181 |