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