Complex classes like Kohana_Service 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 Kohana_Service, and based on these observations, apply Extract Interface, too.
1 | <?php defined('SYSPATH') OR die('No direct script access.'); |
||
16 | class Kohana_Service |
||
17 | { |
||
18 | /** |
||
19 | * Caching services |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | static public $services = array(); |
||
24 | |||
25 | /** |
||
26 | * The cached config file, can be manipulated with the setter |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $_config = array(); |
||
31 | |||
32 | /** |
||
33 | * If this is false the service will not be initialized, but all of it public methods should still be accessible |
||
34 | * |
||
35 | * @var boolean |
||
36 | */ |
||
37 | protected $_enabled = TRUE; |
||
38 | |||
39 | /** |
||
40 | * Whether the service has been initialized, based on this attributes runs init() only once |
||
41 | * |
||
42 | * @var boolean |
||
43 | */ |
||
44 | private $_initialized = FALSE; |
||
45 | |||
46 | /** |
||
47 | * Get the service. Configuration is in the services-manager under the same name. |
||
48 | * The driver name is named the same as the service name |
||
49 | * |
||
50 | * @param string $service_name |
||
51 | * @return Service |
||
52 | */ |
||
53 | public static function factory($service_name) |
||
67 | |||
68 | public static function capitalize_class_name($class_name) |
||
72 | |||
73 | /** |
||
74 | * Getter / setter for enabled attribute |
||
75 | * |
||
76 | * @param bool $enabled |
||
77 | * @return bool|$this |
||
78 | */ |
||
79 | public function enabled($enabled = NULL) |
||
90 | |||
91 | /** |
||
92 | * View::capture clone as it is a protected kohana method |
||
93 | * @param string $file the file to render the contents of |
||
94 | * @param array $variables array of varaiables to be included as local |
||
95 | * @return string the rendered file |
||
96 | */ |
||
97 | public function render_file($file, array $variables = array()) |
||
122 | |||
123 | /** |
||
124 | * Getter / setter for config. |
||
125 | * If you pass an array, merges it with the current configuraton |
||
126 | * If you pass a string returns the config with the specified key |
||
127 | * |
||
128 | * @param [type] $config [description] |
||
|
|||
129 | * @return [type] |
||
130 | */ |
||
131 | public function config($config = NULL) |
||
145 | |||
146 | function __construct($service_name) |
||
151 | |||
152 | /** |
||
153 | * Initialize the service, if it's a php service, the library will be loaded here |
||
154 | * |
||
155 | * @return NULL |
||
156 | */ |
||
157 | public function init() |
||
161 | |||
162 | /** |
||
163 | * Check if the service has been initialized, and if not, run init(), return FALSE if disabled |
||
164 | * |
||
165 | * @return bool |
||
166 | */ |
||
167 | public function initialized() |
||
189 | |||
190 | |||
191 | public function is_enabled_for_robots() |
||
200 | |||
201 | public function is_enabled_for_user() |
||
215 | |||
216 | static public function disable_all() |
||
230 | |||
231 | static public function enable_all() |
||
245 | |||
246 | |||
247 | static public function names() |
||
251 | |||
252 | /** |
||
253 | * Render enabled javascript services, you can specify a list of services to load, otherwise renders all of them |
||
254 | * |
||
255 | * @return string |
||
256 | */ |
||
257 | static public function all_bodies() |
||
280 | |||
281 | static public function all_heads() |
||
304 | } |
||
305 | |||
306 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.