Complex classes like ViewA 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 ViewA, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | abstract class ViewA extends BaseObject implements ViewInterface { |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $sTitle; |
||
27 | |||
28 | /** |
||
29 | * @var ModelA |
||
30 | */ |
||
31 | private $oModel; |
||
32 | |||
33 | /** |
||
34 | * @var ViewHelperA[] |
||
35 | */ |
||
36 | private $aHelpers = array(); |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private $sMainTemplate; |
||
42 | |||
43 | /** |
||
44 | * @var ClassMap |
||
45 | */ |
||
46 | private $oCurrentMap; |
||
47 | |||
48 | /** |
||
49 | * type of view (html, rss, etc) |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $sContentType; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $sFolder; |
||
58 | |||
59 | /** |
||
60 | * @param $sPath |
||
61 | * @throws ExceptionPath |
||
62 | */ |
||
63 | 3 | public function setMainTemplate($sPath) { |
|
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | 1 | public function getMainTemplate() { |
|
76 | |||
77 | /** |
||
78 | * @return string |
||
79 | */ |
||
80 | 1 | public function getContentType() { |
|
83 | |||
84 | /** |
||
85 | * @return string |
||
86 | */ |
||
87 | 3 | public function getViewFolder() { |
|
90 | |||
91 | /** |
||
92 | * @return string |
||
93 | * @throws ExceptionView |
||
94 | */ |
||
95 | 2 | public function getTitle() { |
|
113 | |||
114 | /** |
||
115 | * @param ModelA $oModel |
||
116 | */ |
||
117 | 2 | public function setModel(ModelA $oModel) { |
|
120 | |||
121 | /** |
||
122 | * @throws ExceptionView |
||
123 | * @returns ClassMap |
||
124 | */ |
||
125 | 1 | public function getMap() { |
|
132 | |||
133 | /** |
||
134 | * @param ClassMap $oMap |
||
135 | */ |
||
136 | 2 | public function setMap($oMap) { |
|
139 | |||
140 | 1 | public function registerHelper(ViewHelperA $oHelper) { |
|
143 | |||
144 | 1 | public function __call($sMethodName, $aParameters = array()) { |
|
155 | |||
156 | /** |
||
157 | * @param $sVarName |
||
158 | * @return Base |
||
159 | */ |
||
160 | 1 | public function __get($sVarName) { |
|
170 | |||
171 | /** |
||
172 | * @returns ModelA |
||
173 | */ |
||
174 | 1 | public function getModel() { |
|
180 | |||
181 | // public function setBody ($sText) { |
||
182 | // $this->sBody = $sText; |
||
183 | // } |
||
184 | |||
185 | /** |
||
186 | * @param string $includePath |
||
187 | * @return string |
||
188 | * @throws ExceptionPath |
||
189 | * @throws ExceptionView |
||
190 | */ |
||
191 | 1 | public function fetch($includePath) { |
|
227 | |||
228 | /** |
||
229 | * @return string |
||
230 | * @throws ExceptionView |
||
231 | */ |
||
232 | 1 | public function getOutput() { |
|
245 | |||
246 | /** |
||
247 | * @return string |
||
248 | * @throws ExceptionView |
||
249 | */ |
||
250 | 1 | public function getTemplatePath() { |
|
266 | |||
267 | /** |
||
268 | * @return string |
||
269 | */ |
||
270 | 1 | public function getTemplate() { |
|
277 | |||
278 | /** |
||
279 | * @param string $sPath |
||
280 | */ |
||
281 | 1 | public function setTemplate($sPath) { |
|
288 | |||
289 | /** |
||
290 | * @return string |
||
291 | */ |
||
292 | 1 | public static function getCurrentSiteUri() { |
|
295 | |||
296 | /** |
||
297 | * @return string |
||
298 | */ |
||
299 | 1 | public static function getCurrentUri() { |
|
302 | } |
||
303 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.