Complex classes like BaseController 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 BaseController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
36 | class BaseController extends ContainerAware |
||
|
|||
37 | { |
||
38 | /** |
||
39 | * |
||
40 | * @var \Symfony\Bundle\FrameworkBundle\Routing\Router $router |
||
41 | */ |
||
42 | private $router; |
||
43 | |||
44 | /** |
||
45 | * |
||
46 | * @var \Symfony\Bundle\TwigBundle\Debug\TimedTwigEngine $templating |
||
47 | */ |
||
48 | private $templating; |
||
49 | |||
50 | /** |
||
51 | * |
||
52 | * @var \Symfony\Component\HttpFoundation\Request $request |
||
53 | */ |
||
54 | protected $request; |
||
55 | |||
56 | /** |
||
57 | * |
||
58 | * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher; |
||
59 | */ |
||
60 | protected $dispatcher; |
||
61 | |||
62 | /** |
||
63 | * |
||
64 | * @var \Symfony\Component\Security\Core\SecurityContext $securityContext |
||
65 | */ |
||
66 | private $securityContext; |
||
67 | |||
68 | /** |
||
69 | * |
||
70 | * @var \CCDNForum\ForumBundle\Component\Security\Authorizer $authorizer; |
||
71 | */ |
||
72 | private $authorizer; |
||
73 | |||
74 | /** |
||
75 | * |
||
76 | * @var \CCDNForum\ForumBundle\Model\FrontModel\ForumModel $forumModel |
||
77 | */ |
||
78 | private $forumModel; |
||
79 | |||
80 | /** |
||
81 | * |
||
82 | * @var \CCDNForum\ForumBundle\Model\FrontModel\CategoryModel $categoryModel |
||
83 | */ |
||
84 | private $categoryModel; |
||
85 | |||
86 | /** |
||
87 | * |
||
88 | * @var \CCDNForum\ForumBundle\Model\FrontModel\BoardModel $boardModel |
||
89 | */ |
||
90 | private $boardModel; |
||
91 | |||
92 | /** |
||
93 | * |
||
94 | * @var \CCDNForum\ForumBundle\Model\FrontModel\TopicModel $topicModel |
||
95 | */ |
||
96 | private $topicModel; |
||
97 | |||
98 | /** |
||
99 | * |
||
100 | * @var \CCDNForum\ForumBundle\Model\FrontModel\PostModel $postModel |
||
101 | */ |
||
102 | private $postModel; |
||
103 | |||
104 | /** |
||
105 | * |
||
106 | * @var \CCDNForum\ForumBundle\Model\FrontModel\RegistryModel $registryModel |
||
107 | */ |
||
108 | private $registryModel; |
||
109 | |||
110 | /** |
||
111 | * |
||
112 | * @var \CCDNForum\ForumBundle\Model\FrontModel\SubscriptionModel $subscriptionModel |
||
113 | */ |
||
114 | private $subscriptionModel; |
||
115 | |||
116 | /** |
||
117 | * |
||
118 | * @access protected |
||
119 | * @return \Symfony\Bundle\FrameworkBundle\Routing\Router |
||
120 | */ |
||
121 | protected function getRouter() |
||
129 | |||
130 | /** |
||
131 | * |
||
132 | * @access protected |
||
133 | * @param string $route |
||
134 | * @param Array $params |
||
135 | * @return string |
||
136 | */ |
||
137 | protected function path($route, $params = array()) |
||
141 | |||
142 | /** |
||
143 | * |
||
144 | * @access protected |
||
145 | * @return \Symfony\Bundle\TwigBundle\Debug\TimedTwigEngine |
||
146 | */ |
||
147 | protected function getTemplating() |
||
155 | |||
156 | /** |
||
157 | * |
||
158 | * @access protected |
||
159 | * @return \Symfony\Component\HttpFoundation\Request |
||
160 | */ |
||
161 | protected function getRequest() |
||
169 | |||
170 | /** |
||
171 | * |
||
172 | * @access protected |
||
173 | * @param string $prefix |
||
174 | * @return Array |
||
175 | */ |
||
176 | protected function getCheckedItemIds($prefix = 'check_', $enforceNumericType = true) |
||
198 | |||
199 | /** |
||
200 | * |
||
201 | * @access protected |
||
202 | * @param string $template |
||
203 | * @param Array $params |
||
204 | * @param string $engine |
||
205 | * @return string |
||
206 | */ |
||
207 | protected function renderResponse($template, $params = array(), $engine = null) |
||
211 | |||
212 | /** |
||
213 | * |
||
214 | * @access protected |
||
215 | * @param string $url |
||
216 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
||
217 | */ |
||
218 | protected function redirectResponse($url) |
||
222 | |||
223 | /** |
||
224 | * |
||
225 | * @access protected |
||
226 | * @param string $forumName |
||
227 | * @param \CCDNForum\ForumBundle\Entity\Topic $topic |
||
228 | * @param \CCDNForum\ForumBundle\Entity\Post $post |
||
229 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
||
230 | */ |
||
231 | protected function redirectResponseForTopicOnPageFromPost($forumName, Topic $topic, Post $post) |
||
242 | |||
243 | /** |
||
244 | * |
||
245 | * @access protected |
||
246 | * @return string |
||
247 | */ |
||
248 | protected function getEngine() |
||
252 | |||
253 | /** |
||
254 | * |
||
255 | * @access protected |
||
256 | * @return \Symfony\Component\Security\Core\SecurityContext |
||
257 | */ |
||
258 | protected function getSecurityContext() |
||
266 | |||
267 | /** |
||
268 | * |
||
269 | * @access protected |
||
270 | * @return \Symfony\Component\Security\Core\User\UserInterface |
||
271 | */ |
||
272 | protected function getUser() |
||
276 | |||
277 | /** |
||
278 | * |
||
279 | * @access protected |
||
280 | * @param string $role |
||
281 | * @return bool |
||
282 | */ |
||
283 | protected function isGranted($role) |
||
291 | |||
292 | /** |
||
293 | * |
||
294 | * @access protected |
||
295 | * @param string $role|boolean $role |
||
296 | * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException |
||
297 | */ |
||
298 | protected function isAuthorised($role) |
||
314 | |||
315 | /** |
||
316 | * |
||
317 | * @access protected |
||
318 | * @param \Object $item |
||
319 | * @param string $message |
||
320 | * @return bool |
||
321 | * @throws Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
322 | */ |
||
323 | protected function isFound($item, $message = null) |
||
331 | |||
332 | protected function getQuery($query, $default) |
||
336 | |||
337 | protected function dispatch($name, Event $event) |
||
345 | |||
346 | /** |
||
347 | * |
||
348 | * @access protected |
||
349 | * @return \CCDNForum\ForumBundle\Component\Security\Authorizer |
||
350 | */ |
||
351 | protected function getAuthorizer() |
||
359 | |||
360 | /** |
||
361 | * |
||
362 | * @access protected |
||
363 | * @return \CCDNForum\ForumBundle\Model\FrontModel\ForumModel |
||
364 | */ |
||
365 | protected function getForumModel() |
||
373 | |||
374 | /** |
||
375 | * |
||
376 | * @access protected |
||
377 | * @return \CCDNForum\ForumBundle\Model\FrontModel\CategoryModel |
||
378 | */ |
||
379 | protected function getCategoryModel() |
||
387 | |||
388 | /** |
||
389 | * |
||
390 | * @access protected |
||
391 | * @return \CCDNForum\ForumBundle\Model\FrontModel\BoardModel |
||
392 | */ |
||
393 | protected function getBoardModel() |
||
401 | |||
402 | /** |
||
403 | * |
||
404 | * @access protected |
||
405 | * @return \CCDNForum\ForumBundle\Model\FrontModel\TopicModel |
||
406 | */ |
||
407 | protected function getTopicModel() |
||
415 | |||
416 | /** |
||
417 | * |
||
418 | * @access protected |
||
419 | * @return \CCDNForum\ForumBundle\Model\FrontModel\PostModel |
||
420 | */ |
||
421 | protected function getPostModel() |
||
429 | |||
430 | /** |
||
431 | * |
||
432 | * @access protected |
||
433 | * @return \CCDNForum\ForumBundle\Model\FrontModel\RegistryModel |
||
434 | */ |
||
435 | protected function getRegistryModel() |
||
443 | |||
444 | /** |
||
445 | * |
||
446 | * @access protected |
||
447 | * @return \CCDNForum\ForumBundle\Model\FrontModel\SubscriptionModel |
||
448 | */ |
||
449 | protected function getSubscriptionModel() |
||
457 | |||
458 | /** |
||
459 | * |
||
460 | * @access protected |
||
461 | */ |
||
462 | protected function getCrumbs() |
||
466 | |||
467 | /** |
||
468 | * |
||
469 | * @access protected |
||
470 | * @return \CCDNForum\ForumBundle\Component\Helper\PaginationConfigHelper |
||
471 | */ |
||
472 | protected function getPageHelper() |
||
476 | } |
||
477 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.