Complex classes like ContentController 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 ContentController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class ContentController extends Controller { |
||
26 | |||
27 | protected $dataRecord; |
||
28 | |||
29 | private static $extensions = array('OldPageRedirector'); |
||
30 | |||
31 | private static $allowed_actions = array( |
||
32 | 'successfullyinstalled', |
||
33 | 'deleteinstallfiles', // secured through custom code |
||
34 | 'LoginForm' |
||
35 | ); |
||
36 | |||
37 | /** |
||
38 | * The ContentController will take the URLSegment parameter from the URL and use that to look |
||
39 | * up a SiteTree record. |
||
40 | */ |
||
41 | public function __construct($dataRecord = null) { |
||
55 | |||
56 | /** |
||
57 | * Return the link to this controller, but force the expanded link to be returned so that form methods and |
||
58 | * similar will function properly. |
||
59 | * |
||
60 | * @param string|null $action Action to link to. |
||
61 | * @return string |
||
62 | */ |
||
63 | public function Link($action = null) { |
||
66 | |||
67 | //----------------------------------------------------------------------------------// |
||
68 | // These flexible data methods remove the need for custom code to do simple stuff |
||
69 | |||
70 | /** |
||
71 | * Return the children of a given page. The parent reference can either be a page link or an ID. |
||
72 | * |
||
73 | * @param string|int $parentRef |
||
74 | * @return SS_List |
||
75 | */ |
||
76 | public function ChildrenOf($parentRef) { |
||
85 | |||
86 | /** |
||
87 | * @param string $link |
||
88 | * @return SiteTree |
||
89 | */ |
||
90 | public function Page($link) { |
||
93 | |||
94 | public function init() { |
||
124 | |||
125 | /** |
||
126 | * This acts the same as {@link Controller::handleRequest()}, but if an action cannot be found this will attempt to |
||
127 | * fall over to a child controller in order to provide functionality for nested URLs. |
||
128 | * |
||
129 | * @param SS_HTTPRequest $request |
||
130 | * @param DataModel $model |
||
131 | * @return SS_HTTPResponse |
||
132 | * @throws SS_HTTPResponse_Exception |
||
133 | */ |
||
134 | public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) { |
||
192 | |||
193 | /** |
||
194 | * Get the project name |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | public function project() { |
||
202 | |||
203 | /** |
||
204 | * Returns the associated database record |
||
205 | */ |
||
206 | public function data() { |
||
209 | |||
210 | /*--------------------------------------------------------------------------------*/ |
||
211 | |||
212 | /** |
||
213 | * Returns a fixed navigation menu of the given level. |
||
214 | * @param int $level Menu level to return. |
||
215 | * @return ArrayList |
||
216 | */ |
||
217 | public function getMenu($level = 1) { |
||
251 | |||
252 | public function Menu($level) { |
||
255 | |||
256 | /** |
||
257 | * Returns the default log-in form. |
||
258 | * |
||
259 | * @todo Check if here should be returned just the default log-in form or |
||
260 | * all available log-in forms (also OpenID...) |
||
261 | */ |
||
262 | public function LoginForm() { |
||
265 | |||
266 | public function SilverStripeNavigator() { |
||
267 | $member = Member::currentUser(); |
||
268 | $items = ''; |
||
269 | $message = ''; |
||
270 | |||
271 | if(Director::isDev() || Permission::check('CMS_ACCESS_CMSMain') || Permission::check('VIEW_DRAFT_CONTENT')) { |
||
272 | if($this->dataRecord) { |
||
273 | Requirements::css(CMS_DIR . '/client/dist/styles/SilverStripeNavigator.css'); |
||
274 | Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js'); |
||
275 | Requirements::javascript(CMS_DIR . '/client/dist/js/SilverStripeNavigator.js'); |
||
276 | |||
277 | $return = $nav = SilverStripeNavigator::get_for_record($this->dataRecord); |
||
278 | $items = $return['items']; |
||
279 | $message = $return['message']; |
||
280 | } |
||
281 | |||
282 | if($member) { |
||
283 | $firstname = Convert::raw2xml($member->FirstName); |
||
284 | $surname = Convert::raw2xml($member->Surname); |
||
285 | $logInMessage = _t('ContentController.LOGGEDINAS', 'Logged in as') ." {$firstname} {$surname} - <a href=\"Security/logout\">". _t('ContentController.LOGOUT', 'Log out'). "</a>"; |
||
286 | } else { |
||
287 | $logInMessage = sprintf( |
||
288 | '%s - <a href="%s">%s</a>' , |
||
289 | _t('ContentController.NOTLOGGEDIN', 'Not logged in') , |
||
290 | Config::inst()->get('Security', 'login_url'), |
||
291 | _t('ContentController.LOGIN', 'Login') ."</a>" |
||
292 | ); |
||
293 | } |
||
294 | $viewPageIn = _t('ContentController.VIEWPAGEIN', 'View Page in:'); |
||
295 | |||
296 | return <<<HTML |
||
297 | <div id="SilverStripeNavigator"> |
||
298 | <div class="holder"> |
||
299 | <div id="logInStatus"> |
||
300 | $logInMessage |
||
301 | </div> |
||
302 | |||
303 | <div id="switchView" class="bottomTabs"> |
||
304 | $viewPageIn |
||
305 | $items |
||
306 | </div> |
||
307 | </div> |
||
308 | </div> |
||
309 | $message |
||
310 | HTML; |
||
311 | |||
312 | // On live sites we should still see the archived message |
||
313 | } else { |
||
314 | if($date = Versioned::current_archived_date()) { |
||
315 | Requirements::css(CMS_DIR . '/client/dist/styles/SilverStripeNavigator.css'); |
||
316 | $dateObj = Datetime::create($date, null); |
||
317 | // $dateObj->setVal($date); |
||
318 | return "<div id=\"SilverStripeNavigatorMessage\">". _t('ContentController.ARCHIVEDSITEFROM') ."<br>" . $dateObj->Nice() . "</div>"; |
||
319 | } |
||
320 | } |
||
321 | } |
||
322 | |||
323 | public function SiteConfig() { |
||
330 | |||
331 | /** |
||
332 | * Returns an RFC1766 compliant locale string, e.g. 'fr-CA'. |
||
333 | * Inspects the associated {@link dataRecord} for a {@link SiteTree->Locale} value if present, |
||
334 | * and falls back to {@link Translatable::get_current_locale()} or {@link i18n::default_locale()}, |
||
335 | * depending if Translatable is enabled. |
||
336 | * |
||
337 | * Suitable for insertion into lang= and xml:lang= |
||
338 | * attributes in HTML or XHTML output. |
||
339 | * |
||
340 | * @return string |
||
341 | */ |
||
342 | public function ContentLocale() { |
||
353 | |||
354 | |||
355 | /** |
||
356 | * Return an SSViewer object to render the template for the current page. |
||
357 | * |
||
358 | * @param $action string |
||
359 | * |
||
360 | * @return SSViewer |
||
361 | */ |
||
362 | public function getViewer($action) { |
||
387 | |||
388 | |||
389 | /** |
||
390 | * This action is called by the installation system |
||
391 | */ |
||
392 | public function successfullyinstalled() { |
||
416 | |||
417 | public function deleteinstallfiles() { |
||
456 | } |
||
457 |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.