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 |
||
64 | function init() |
||
65 | { |
||
66 | // list of configured options |
||
67 | $configured = array(); |
||
68 | |||
69 | // Load default settings |
||
70 | if ( ! ($this->setting = @include( $GLOBALS['xoops']->path( "var/configs/tinymce.php" ) ) ) ) { |
||
71 | $this->setting = include dirname(__FILE__) . "/settings.php"; |
||
72 | } |
||
73 | |||
74 | // get editor language (from ...) |
||
75 | if (is_readable(XOOPS_ROOT_PATH . $this->rootpath . '/langs/' . $this->config["language"] . '.js')) { |
||
76 | $this->setting["language"] = $this->config["language"]; |
||
77 | $configured[] = "language"; |
||
78 | } |
||
79 | |||
80 | $this->setting["content_css"] = implode( ",", $this->loadCss() ); |
||
81 | $configured[] = "content_css"; |
||
82 | |||
83 | if ( !empty($this->config["theme"]) && is_dir(XOOPS_ROOT_PATH . $this->rootpath . "/themes/" . $this->config["theme"]) ) { |
||
84 | $this->setting["theme"] = $this->config["theme"]; |
||
85 | $configured[] = "theme"; |
||
86 | } |
||
87 | |||
88 | if (!empty($this->config["mode"])) { |
||
89 | $this->setting["mode"] = $this->config["mode"]; |
||
90 | $configured[] = "mode"; |
||
91 | } |
||
92 | |||
93 | // load all plugins except the plugins in setting["exclude_plugins"] |
||
94 | $this->setting["plugins"] = implode(",", $this->loadPlugins()); |
||
95 | $configured[] = "plugins"; |
||
96 | |||
97 | if ( $this->setting["theme"] != "simple" ) { |
||
98 | if (empty($this->config["buttons"])) { |
||
99 | $this->config["buttons"][] = array( |
||
100 | "before" => "", |
||
101 | "add" => "", |
||
102 | ); |
||
103 | $this->config["buttons"][] = array( |
||
104 | "before" => "", |
||
105 | "add" => "", |
||
106 | ); |
||
107 | $this->config["buttons"][] = array( |
||
108 | "before" => "", |
||
109 | "add" => "", |
||
110 | ); |
||
111 | } |
||
112 | $i = 0; |
||
113 | foreach ($this->config["buttons"] as $button) { |
||
114 | $i++; |
||
115 | if (isset($button["before"])) { |
||
116 | $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}_add_before"] = $button["before"]; |
||
117 | } |
||
118 | if (isset($button["add"])) { |
||
119 | $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}_add"] = $button["add"]; |
||
120 | } |
||
121 | if (isset($button[""])) { |
||
122 | $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}"] = $button[""]; |
||
123 | } |
||
124 | } |
||
125 | $configured[] = "buttons"; |
||
126 | |||
127 | if (isset($this->config["toolbar_location"])) { |
||
128 | $this->setting["theme_" . $this->setting["theme"] . "_toolbar_location"] = $this->config["toolbar_location"]; |
||
129 | $configured[] = "toolbar_location"; |
||
130 | } else { |
||
131 | $this->setting["theme_" . $this->setting["theme"] . "_toolbar_location"] = "top"; |
||
132 | } |
||
133 | |||
134 | if (isset($this->config["toolbar_align"])) { |
||
135 | $this->setting["theme_" . $this->setting["theme"] . "_toolbar_align"] = $this->config["toolbar_align"]; |
||
136 | $configured[] = "toolbar_align"; |
||
137 | } else { |
||
138 | $this->setting["theme_" . $this->setting["theme"] . "_toolbar_align"] = "left"; |
||
139 | } |
||
140 | |||
141 | if (isset($this->config["statusbar_location"])) { |
||
142 | $this->setting["theme_" . $this->setting["theme"] . "_statusbar_location"] = $this->config["statusbar_location"]; |
||
143 | $configured[] = "statusbar_location"; |
||
144 | } |
||
145 | |||
146 | if (isset($this->config["path_location"])) { |
||
147 | $this->setting["theme_" . $this->setting["theme"] . "_path_location"] = $this->config["path_location"]; |
||
148 | $configured[] = "path_location"; |
||
149 | } |
||
150 | |||
151 | if (isset($this->config["resize_horizontal"])) { |
||
152 | $this->setting["theme_" . $this->setting["theme"] . "_resize_horizontal"] = $this->config["resize_horizontal"]; |
||
153 | $configured[] = "resize_horizontal"; |
||
154 | } |
||
155 | |||
156 | if (isset($this->config["resizing"])) { |
||
157 | $this->setting["theme_" . $this->setting["theme"] . "_resizing"] = $this->config["resizing"]; |
||
158 | $configured[] = "resizing"; |
||
159 | } |
||
160 | |||
161 | if (!empty($this->config["fonts"])) { |
||
162 | $this->setting["theme_" . $this->setting["theme"] . "_fonts"] = $this->config["fonts"]; |
||
163 | $configured[] = "fonts"; |
||
164 | } |
||
165 | |||
166 | for ($i=1 ; $i <= 4 ; $i++ ) { |
||
167 | $buttons = array(); |
||
168 | if ( isset($this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}"]) ) { |
||
169 | $checklist = explode(",", $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}"] ); |
||
170 | foreach ( $checklist as $plugin ) { |
||
171 | if ( strpos( strtolower($plugin), "xoops") != false ) { |
||
172 | if ( in_array( $plugin, $this->xoopsPlugins ) ) { |
||
173 | $buttons[] = $plugin; |
||
174 | } |
||
175 | } else { |
||
176 | $buttons[] = $plugin; |
||
177 | } |
||
178 | } |
||
179 | $this->setting["theme_" . $this->setting["theme"] . "_buttons{$i}"] = implode(",", $buttons); |
||
180 | } |
||
181 | } |
||
182 | } |
||
183 | |||
184 | $configured = array_unique($configured); |
||
185 | foreach ($this->config as $key => $val) { |
||
186 | if (isset($this->setting[$key]) || in_array($key, $configured)) { |
||
187 | continue; |
||
188 | } |
||
189 | $this->setting[$key] = $val; |
||
190 | } |
||
191 | |||
192 | if (!is_dir(XOOPS_ROOT_PATH . $this->rootpath . "/themes/" . $this->setting["theme"] . '/docs/' . $this->setting["language"] . '/')) { |
||
193 | $this->setting["docs_language"] = "en"; |
||
194 | } |
||
195 | |||
196 | unset($this->config, $configured); |
||
197 | |||
198 | return true; |
||
199 | } |
||
200 | |||
341 |
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.