Complex classes like AppHelper 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 AppHelper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class AppHelper extends Base |
||
21 | { |
||
22 | /** |
||
23 | * Get setting variable. |
||
24 | * |
||
25 | * @param string $param |
||
26 | * @param mixed $default_value |
||
27 | * |
||
28 | * @return mixed |
||
29 | */ |
||
30 | public function setting($param, $default_value = '') |
||
34 | |||
35 | /** |
||
36 | * Set active class if request is in path. |
||
37 | * |
||
38 | * @param string $controller |
||
39 | * @param string $action |
||
40 | * @param string $slug |
||
41 | * @param string $plugin |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | public function setActive($controller, $action = '', $slug = '', $plugin = '') |
||
74 | |||
75 | /** |
||
76 | * Get plugin name from route. |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | public function getPluginName() |
||
84 | |||
85 | /** |
||
86 | * Get router controller. |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | public function getRouterController() |
||
94 | |||
95 | /** |
||
96 | * Get router action. |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | public function getRouterAction() |
||
104 | |||
105 | /** |
||
106 | * Get javascript language code. |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | public function jsLang() |
||
114 | |||
115 | /** |
||
116 | * Get date format for Jquery DatePicker. |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getJsDateFormat() |
||
129 | |||
130 | /** |
||
131 | * Get time format for Jquery Plugin DateTimePicker. |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | public function getJsTimeFormat() |
||
145 | |||
146 | /** |
||
147 | * Get current skin. |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | public function getSkin() |
||
155 | |||
156 | /** |
||
157 | * Get current skin. |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | public function getLayout() |
||
165 | |||
166 | /** |
||
167 | * Get default view of project. |
||
168 | * |
||
169 | * @return array |
||
170 | */ |
||
171 | public function getProjectDefaultView($slug = '', $forController = false) |
||
202 | |||
203 | /** |
||
204 | * Get current dashboard. |
||
205 | * |
||
206 | * @return array |
||
207 | */ |
||
208 | public function getDashboard($forController = false) |
||
241 | |||
242 | /** |
||
243 | * Get current timezone. |
||
244 | * |
||
245 | * @return string |
||
246 | */ |
||
247 | public function getTimezone() |
||
251 | |||
252 | /** |
||
253 | * Get session flash message. |
||
254 | * |
||
255 | * @return string |
||
256 | */ |
||
257 | public function flashMessage() |
||
278 | } |
||
279 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.