| Conditions | 28 |
| Paths | > 20000 |
| Total Lines | 139 |
| Code Lines | 89 |
| Lines | 99 |
| Ratio | 71.22 % |
| Tests | 0 |
| CRAP Score | 812 |
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 |
||
| 66 | function init() |
||
| 67 | { |
||
| 68 | $xoops = Xoops::getInstance(); |
||
| 69 | // list of configured options |
||
| 70 | $configured = array(); |
||
| 71 | |||
| 72 | $xoops_root_path = \XoopsBaseConfig::get('root-path'); |
||
| 73 | |||
| 74 | // Load default settings |
||
| 75 | View Code Duplication | if ( ! ($this->setting = @include( $xoops->path( "var/configs/tinymce.php" ) ) ) ) { |
|
| 76 | $this->setting = include __DIR__ . "/settings.php"; |
||
| 77 | } |
||
| 78 | |||
| 79 | // get editor language (from ...) |
||
| 80 | if (is_readable($xoops_root_path . $this->rootpath . '/langs/' . $this->config["language"] . '.js')) { |
||
| 81 | $this->setting["language"] = $this->config["language"]; |
||
| 82 | $configured[] = "language"; |
||
| 83 | } |
||
| 84 | |||
| 85 | $this->setting["content_css"] = implode( ",", $this->loadCss()) . ',' . $xoops->url('xoops.css'); |
||
| 86 | $configured[] = "content_css"; |
||
| 87 | |||
| 88 | if ( !empty($this->config["theme"]) && is_dir($xoops_root_path . $this->rootpath . "/themes/" . $this->config["theme"]) ) { |
||
| 89 | $this->setting["theme"] = $this->config["theme"]; |
||
| 90 | $configured[] = "theme"; |
||
| 91 | } |
||
| 92 | |||
| 93 | View Code Duplication | if (!empty($this->config["mode"])) { |
|
| 94 | $this->setting["mode"] = $this->config["mode"]; |
||
| 95 | $configured[] = "mode"; |
||
| 96 | } |
||
| 97 | |||
| 98 | // load all plugins except the plugins in setting["exclude_plugins"] |
||
| 99 | $this->setting["plugins"] = implode(",", $this->loadPlugins()); |
||
| 100 | $configured[] = "plugins"; |
||
| 101 | |||
| 102 | View Code Duplication | if ( $this->setting["theme"] !== "simple" ) { |
|
| 103 | if (empty($this->config["buttons"])) { |
||
| 104 | $this->config["buttons"][] = array( |
||
| 105 | "before" => "", |
||
| 106 | "add" => "", |
||
| 107 | ); |
||
| 108 | $this->config["buttons"][] = array( |
||
| 109 | "before" => "", |
||
| 110 | "add" => "", |
||
| 111 | ); |
||
| 112 | $this->config["buttons"][] = array( |
||
| 113 | "before" => "", |
||
| 114 | "add" => "", |
||
| 115 | ); |
||
| 116 | } |
||
| 117 | $i = 0; |
||
| 118 | foreach ($this->config["buttons"] as $button) { |
||
| 119 | $i++; |
||
| 120 | if (isset($button["before"])) { |
||
| 121 | $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}_add_before"] = $button["before"]; |
||
| 122 | } |
||
| 123 | if (isset($button["add"])) { |
||
| 124 | $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}_add"] = $button["add"]; |
||
| 125 | } |
||
| 126 | if (isset($button[""])) { |
||
| 127 | $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}"] = $button[""]; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | $configured[] = "buttons"; |
||
| 131 | |||
| 132 | if (isset($this->config["toolbar_location"])) { |
||
| 133 | $this->setting["theme_" . $this->setting["theme"] . "_toolbar_location"] = $this->config["toolbar_location"]; |
||
| 134 | $configured[] = "toolbar_location"; |
||
| 135 | } else { |
||
| 136 | $this->setting["theme_" . $this->setting["theme"] . "_toolbar_location"] = "top"; |
||
| 137 | } |
||
| 138 | |||
| 139 | if (isset($this->config["toolbar_align"])) { |
||
| 140 | $this->setting["theme_" . $this->setting["theme"] . "_toolbar_align"] = $this->config["toolbar_align"]; |
||
| 141 | $configured[] = "toolbar_align"; |
||
| 142 | } else { |
||
| 143 | $this->setting["theme_" . $this->setting["theme"] . "_toolbar_align"] = "left"; |
||
| 144 | } |
||
| 145 | |||
| 146 | if (isset($this->config["statusbar_location"])) { |
||
| 147 | $this->setting["theme_" . $this->setting["theme"] . "_statusbar_location"] = $this->config["statusbar_location"]; |
||
| 148 | $configured[] = "statusbar_location"; |
||
| 149 | } |
||
| 150 | |||
| 151 | if (isset($this->config["path_location"])) { |
||
| 152 | $this->setting["theme_" . $this->setting["theme"] . "_path_location"] = $this->config["path_location"]; |
||
| 153 | $configured[] = "path_location"; |
||
| 154 | } |
||
| 155 | |||
| 156 | if (isset($this->config["resize_horizontal"])) { |
||
| 157 | $this->setting["theme_" . $this->setting["theme"] . "_resize_horizontal"] = $this->config["resize_horizontal"]; |
||
| 158 | $configured[] = "resize_horizontal"; |
||
| 159 | } |
||
| 160 | |||
| 161 | if (isset($this->config["resizing"])) { |
||
| 162 | $this->setting["theme_" . $this->setting["theme"] . "_resizing"] = $this->config["resizing"]; |
||
| 163 | $configured[] = "resizing"; |
||
| 164 | } |
||
| 165 | |||
| 166 | if (!empty($this->config["fonts"])) { |
||
| 167 | $this->setting["theme_" . $this->setting["theme"] . "_fonts"] = $this->config["fonts"]; |
||
| 168 | $configured[] = "fonts"; |
||
| 169 | } |
||
| 170 | |||
| 171 | for ($i=1 ; $i <= 4 ; $i++ ) { |
||
| 172 | $buttons = array(); |
||
| 173 | if ( isset($this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}"]) ) { |
||
| 174 | $checklist = explode(",", $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}"] ); |
||
| 175 | foreach ( $checklist as $plugin ) { |
||
| 176 | if ( strpos( strtolower($plugin), "xoops") !== false ) { |
||
| 177 | if ( in_array( $plugin, $this->xoopsPlugins ) ) { |
||
| 178 | $buttons[] = $plugin; |
||
| 179 | } |
||
| 180 | } else { |
||
| 181 | $buttons[] = $plugin; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}"] = implode(",", $buttons); |
||
| 185 | } |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 189 | $configured = array_unique($configured); |
||
| 190 | View Code Duplication | foreach ($this->config as $key => $val) { |
|
| 191 | if (isset($this->setting[$key]) || in_array($key, $configured)) { |
||
| 192 | continue; |
||
| 193 | } |
||
| 194 | $this->setting[$key] = $val; |
||
| 195 | } |
||
| 196 | |||
| 197 | if (!is_dir($xoops_root_path . $this->rootpath . "/themes/" . $this->setting["theme"] . '/docs/' . $this->setting["language"] . '/')) { |
||
| 198 | $this->setting["docs_language"] = "en"; |
||
| 199 | } |
||
| 200 | |||
| 201 | unset($this->config, $configured); |
||
| 202 | |||
| 203 | return true; |
||
| 204 | } |
||
| 205 | |||
| 319 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.