| Conditions | 28 |
| Paths | > 20000 |
| Total Lines | 136 |
| Lines | 136 |
| Ratio | 100 % |
| 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 |
||
| 86 | function init() |
||
| 87 | { |
||
| 88 | // list of configured options |
||
| 89 | $configured = array(); |
||
| 90 | |||
| 91 | // Load default settings |
||
| 92 | if ( ! ($this->setting = @include( $GLOBALS['xoops']->path( "var/configs/tinymce.php" ) ) ) ) { |
||
| 93 | $this->setting = include __DIR__ . "/settings.php"; |
||
| 94 | } |
||
| 95 | |||
| 96 | // get editor language (from ...) |
||
| 97 | if (isset($this->config["language"]) && is_readable(XOOPS_ROOT_PATH . $this->rootpath . '/langs/' . $this->config["language"] . '.js')) { |
||
| 98 | $this->setting["language"] = $this->config["language"]; |
||
| 99 | $configured[] = "language"; |
||
| 100 | } |
||
| 101 | |||
| 102 | $this->setting["content_css"] = implode( ",", $this->loadCss() ); |
||
| 103 | $configured[] = "content_css"; |
||
| 104 | |||
| 105 | if ( !empty($this->config["theme"]) && is_dir(XOOPS_ROOT_PATH . $this->rootpath . "/themes/" . $this->config["theme"]) ) { |
||
| 106 | $this->setting["theme"] = $this->config["theme"]; |
||
| 107 | $configured[] = "theme"; |
||
| 108 | } |
||
| 109 | |||
| 110 | if (!empty($this->config["mode"])) { |
||
| 111 | $this->setting["mode"] = $this->config["mode"]; |
||
| 112 | $configured[] = "mode"; |
||
| 113 | } |
||
| 114 | |||
| 115 | // load all plugins except the plugins in setting["exclude_plugins"] |
||
| 116 | $this->setting["plugins"] = implode(",", $this->loadPlugins()); |
||
| 117 | $configured[] = "plugins"; |
||
| 118 | |||
| 119 | if ($this->setting["theme"] != "simple") { |
||
| 120 | if (empty($this->config["buttons"])) { |
||
| 121 | $this->config["buttons"][] = array( |
||
| 122 | "before" => "", |
||
| 123 | "add" => "", |
||
| 124 | ); |
||
| 125 | $this->config["buttons"][] = array( |
||
| 126 | "before" => "", |
||
| 127 | "add" => "", |
||
| 128 | ); |
||
| 129 | $this->config["buttons"][] = array( |
||
| 130 | "before" => "", |
||
| 131 | "add" => "", |
||
| 132 | ); |
||
| 133 | } |
||
| 134 | $i = 0; |
||
| 135 | foreach ($this->config["buttons"] as $button) { |
||
| 136 | $i++; |
||
| 137 | if (isset($button["before"])) { |
||
| 138 | $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}_add_before"] = $button["before"]; |
||
| 139 | } |
||
| 140 | if (isset($button["add"])) { |
||
| 141 | $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}_add"] = $button["add"]; |
||
| 142 | } |
||
| 143 | if (isset($button[""])) { |
||
| 144 | $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}"] = $button[""]; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | $configured[] = "buttons"; |
||
| 148 | |||
| 149 | if (isset($this->config["toolbar_location"])) { |
||
| 150 | $this->setting["theme_" . $this->setting["theme"] . "_toolbar_location"] = $this->config["toolbar_location"]; |
||
| 151 | $configured[] = "toolbar_location"; |
||
| 152 | } else { |
||
| 153 | $this->setting["theme_" . $this->setting["theme"] . "_toolbar_location"] = "top"; |
||
| 154 | } |
||
| 155 | |||
| 156 | if (isset($this->config["toolbar_align"])) { |
||
| 157 | $this->setting["theme_" . $this->setting["theme"] . "_toolbar_align"] = $this->config["toolbar_align"]; |
||
| 158 | $configured[] = "toolbar_align"; |
||
| 159 | } else { |
||
| 160 | $this->setting["theme_" . $this->setting["theme"] . "_toolbar_align"] = "left"; |
||
| 161 | } |
||
| 162 | |||
| 163 | if (isset($this->config["statusbar_location"])) { |
||
| 164 | $this->setting["theme_" . $this->setting["theme"] . "_statusbar_location"] = $this->config["statusbar_location"]; |
||
| 165 | $configured[] = "statusbar_location"; |
||
| 166 | } |
||
| 167 | |||
| 168 | if (isset($this->config["path_location"])) { |
||
| 169 | $this->setting["theme_" . $this->setting["theme"] . "_path_location"] = $this->config["path_location"]; |
||
| 170 | $configured[] = "path_location"; |
||
| 171 | } |
||
| 172 | |||
| 173 | if (isset($this->config["resize_horizontal"])) { |
||
| 174 | $this->setting["theme_" . $this->setting["theme"] . "_resize_horizontal"] = $this->config["resize_horizontal"]; |
||
| 175 | $configured[] = "resize_horizontal"; |
||
| 176 | } |
||
| 177 | |||
| 178 | if (isset($this->config["resizing"])) { |
||
| 179 | $this->setting["theme_" . $this->setting["theme"] . "_resizing"] = $this->config["resizing"]; |
||
| 180 | $configured[] = "resizing"; |
||
| 181 | } |
||
| 182 | |||
| 183 | if (!empty($this->config["fonts"])) { |
||
| 184 | $this->setting["theme_" . $this->setting["theme"] . "_fonts"] = $this->config["fonts"]; |
||
| 185 | $configured[] = "fonts"; |
||
| 186 | } |
||
| 187 | |||
| 188 | for ($i=1 ; $i <= 4 ; $i++) { |
||
| 189 | $buttons = array(); |
||
| 190 | if ( isset($this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}"]) ) { |
||
| 191 | $checklist = explode(",", $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}"] ); |
||
| 192 | foreach ($checklist as $plugin) { |
||
| 193 | if ( strpos( strtolower($plugin), "xoops") != false ) { |
||
| 194 | if ( in_array( $plugin, $this->xoopsPlugins ) ) { |
||
| 195 | $buttons[] = $plugin; |
||
| 196 | } |
||
| 197 | } else { |
||
| 198 | $buttons[] = $plugin; |
||
| 199 | } |
||
| 200 | } |
||
| 201 | $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}"] = implode(",", $buttons); |
||
| 202 | } |
||
| 203 | } |
||
| 204 | } |
||
| 205 | |||
| 206 | $configured = array_unique($configured); |
||
| 207 | foreach ($this->config as $key => $val) { |
||
| 208 | if (isset($this->setting[$key]) || in_array($key, $configured)) { |
||
| 209 | continue; |
||
| 210 | } |
||
| 211 | $this->setting[$key] = $val; |
||
| 212 | } |
||
| 213 | |||
| 214 | if (!is_dir(XOOPS_ROOT_PATH . $this->rootpath . "/themes/" . $this->setting["theme"] . '/docs/' . $this->setting["language"] . '/')) { |
||
| 215 | $this->setting["docs_language"] = "en"; |
||
| 216 | } |
||
| 217 | |||
| 218 | unset($this->config, $configured); |
||
| 219 | |||
| 220 | return true; |
||
| 221 | } |
||
| 222 | |||
| 396 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.