Complex classes like DokuWiki_PluginTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DokuWiki_PluginTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | trait DokuWiki_PluginTrait { |
||
8 | |||
9 | protected $localised = false; // set to true by setupLocale() after loading language dependent strings |
||
10 | protected $lang = array(); // array to hold language dependent strings, best accessed via ->getLang() |
||
11 | protected $configloaded = false; // set to true by loadConfig() after loading plugin configuration variables |
||
12 | protected $conf = array(); // array to hold plugin settings, best accessed via ->getConf() |
||
13 | |||
14 | /** |
||
15 | * @see DokuWiki_PluginInterface::getInfo() |
||
16 | */ |
||
17 | public function getInfo() { |
||
32 | |||
33 | /** |
||
34 | * @see DokuWiki_PluginInterface::isSingleton() |
||
35 | */ |
||
36 | public function isSingleton() { |
||
39 | |||
40 | /** |
||
41 | * @see DokuWiki_PluginInterface::loadHelper() |
||
42 | */ |
||
43 | public function loadHelper($name, $msg = true) { |
||
48 | |||
49 | // region introspection methods |
||
50 | |||
51 | /** |
||
52 | * @see DokuWiki_PluginInterface::getPluginType() |
||
53 | */ |
||
54 | public function getPluginType() { |
||
58 | |||
59 | /** |
||
60 | * @see DokuWiki_PluginInterface::getPluginName() |
||
61 | */ |
||
62 | public function getPluginName() { |
||
66 | |||
67 | /** |
||
68 | * @see DokuWiki_PluginInterface::getPluginComponent() |
||
69 | */ |
||
70 | public function getPluginComponent() { |
||
74 | |||
75 | // endregion |
||
76 | // region localization methods |
||
77 | |||
78 | /** |
||
79 | * @see DokuWiki_PluginInterface::getLang() |
||
80 | */ |
||
81 | public function getLang($id) { |
||
86 | |||
87 | /** |
||
88 | * @see DokuWiki_PluginInterface::locale_xhtml() |
||
89 | */ |
||
90 | public function locale_xhtml($id) { |
||
93 | |||
94 | /** |
||
95 | * @see DokuWiki_PluginInterface::localFN() |
||
96 | */ |
||
97 | public function localFN($id, $ext = 'txt') { |
||
110 | |||
111 | /** |
||
112 | * @see DokuWiki_PluginInterface::setupLocale() |
||
113 | */ |
||
114 | public function setupLocale() { |
||
142 | |||
143 | // endregion |
||
144 | // region configuration methods |
||
145 | |||
146 | /** |
||
147 | * @see DokuWiki_PluginInterface::getConf() |
||
148 | */ |
||
149 | public function getConf($setting, $notset = false) { |
||
161 | |||
162 | /** |
||
163 | * @see DokuWiki_PluginInterface::loadConfig() |
||
164 | */ |
||
165 | public function loadConfig() { |
||
179 | |||
180 | /** |
||
181 | * read the plugin's default configuration settings from conf/default.php |
||
182 | * this function is automatically called through getConf() |
||
183 | * |
||
184 | * @return array setting => value |
||
185 | */ |
||
186 | protected function readDefaultSettings() { |
||
197 | |||
198 | // endregion |
||
199 | // region output methods |
||
200 | |||
201 | /** |
||
202 | * @see DokuWiki_PluginInterface::email() |
||
203 | */ |
||
204 | public function email($email, $name = '', $class = '', $more = '') { |
||
211 | |||
212 | /** |
||
213 | * @see DokuWiki_PluginInterface::external_link() |
||
214 | */ |
||
215 | public function external_link($link, $title = '', $class = '', $target = '', $more = '') { |
||
229 | |||
230 | /** |
||
231 | * @see DokuWiki_PluginInterface::render_text() |
||
232 | */ |
||
233 | public function render_text($text, $format = 'xhtml') { |
||
236 | |||
237 | // endregion |
||
238 | } |
||
239 |
If you suppress an error, we recommend checking for the error condition explicitly: