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