Complex classes like 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 PluginTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 8 | trait PluginTrait  | 
            ||
| 9 | { | 
            ||
| 10 | |||
| 11 | protected $localised = false; // set to true by setupLocale() after loading language dependent strings  | 
            ||
| 12 | protected $lang = array(); // array to hold language dependent strings, best accessed via ->getLang()  | 
            ||
| 13 | protected $configloaded = false; // set to true by loadConfig() after loading plugin configuration variables  | 
            ||
| 14 | protected $conf = array(); // array to hold plugin settings, best accessed via ->getConf()  | 
            ||
| 15 | |||
| 16 | /**  | 
            ||
| 17 | * @see PluginInterface::getInfo()  | 
            ||
| 18 | */  | 
            ||
| 19 | public function getInfo()  | 
            ||
| 35 | |||
| 36 | /**  | 
            ||
| 37 | * @see PluginInterface::isSingleton()  | 
            ||
| 38 | */  | 
            ||
| 39 | public function isSingleton()  | 
            ||
| 43 | |||
| 44 | /**  | 
            ||
| 45 | * @see PluginInterface::loadHelper()  | 
            ||
| 46 | */  | 
            ||
| 47 | public function loadHelper($name, $msg = true)  | 
            ||
| 53 | |||
| 54 | // region introspection methods  | 
            ||
| 55 | |||
| 56 | /**  | 
            ||
| 57 | * @see PluginInterface::getPluginType()  | 
            ||
| 58 | */  | 
            ||
| 59 | public function getPluginType()  | 
            ||
| 64 | |||
| 65 | /**  | 
            ||
| 66 | * @see PluginInterface::getPluginName()  | 
            ||
| 67 | */  | 
            ||
| 68 | public function getPluginName()  | 
            ||
| 73 | |||
| 74 | /**  | 
            ||
| 75 | * @see PluginInterface::getPluginComponent()  | 
            ||
| 76 | */  | 
            ||
| 77 | public function getPluginComponent()  | 
            ||
| 82 | |||
| 83 | // endregion  | 
            ||
| 84 | // region localization methods  | 
            ||
| 85 | |||
| 86 | /**  | 
            ||
| 87 | * @see PluginInterface::getLang()  | 
            ||
| 88 | */  | 
            ||
| 89 | public function getLang($id)  | 
            ||
| 95 | |||
| 96 | /**  | 
            ||
| 97 | * @see PluginInterface::locale_xhtml()  | 
            ||
| 98 | */  | 
            ||
| 99 | public function locale_xhtml($id)  | 
            ||
| 103 | |||
| 104 | /**  | 
            ||
| 105 | * @see PluginInterface::localFN()  | 
            ||
| 106 | */  | 
            ||
| 107 | public function localFN($id, $ext = 'txt')  | 
            ||
| 121 | |||
| 122 | /**  | 
            ||
| 123 | * @see PluginInterface::setupLocale()  | 
            ||
| 124 | */  | 
            ||
| 125 | public function setupLocale()  | 
            ||
| 154 | |||
| 155 | // endregion  | 
            ||
| 156 | // region configuration methods  | 
            ||
| 157 | |||
| 158 | /**  | 
            ||
| 159 | * @see PluginInterface::getConf()  | 
            ||
| 160 | */  | 
            ||
| 161 | public function getConf($setting, $notset = false)  | 
            ||
| 174 | |||
| 175 | /**  | 
            ||
| 176 | * @see PluginInterface::loadConfig()  | 
            ||
| 177 | */  | 
            ||
| 178 | public function loadConfig()  | 
            ||
| 193 | |||
| 194 | /**  | 
            ||
| 195 | * read the plugin's default configuration settings from conf/default.php  | 
            ||
| 196 | * this function is automatically called through getConf()  | 
            ||
| 197 | *  | 
            ||
| 198 | * @return array setting => value  | 
            ||
| 199 | */  | 
            ||
| 200 | protected function readDefaultSettings()  | 
            ||
| 212 | |||
| 213 | // endregion  | 
            ||
| 214 | // region output methods  | 
            ||
| 215 | |||
| 216 | /**  | 
            ||
| 217 | * @see PluginInterface::email()  | 
            ||
| 218 | */  | 
            ||
| 219 | public function email($email, $name = '', $class = '', $more = '')  | 
            ||
| 227 | |||
| 228 | /**  | 
            ||
| 229 | * @see PluginInterface::external_link()  | 
            ||
| 230 | */  | 
            ||
| 231 | public function external_link($link, $title = '', $class = '', $target = '', $more = '')  | 
            ||
| 246 | |||
| 247 | /**  | 
            ||
| 248 | * @see PluginInterface::render_text()  | 
            ||
| 249 | */  | 
            ||
| 250 | public function render_text($text, $format = 'xhtml')  | 
            ||
| 254 | |||
| 255 | // endregion  | 
            ||
| 256 | }  | 
            ||
| 257 |