Complex classes like Admin 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 Admin, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | abstract class Admin |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Admin Section Icon. |
||
| 14 | * |
||
| 15 | * Font Awesome Defined Icon, eg 'user' = 'fa-user' |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $icon; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Title of Admin Section. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $title; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Plural Title of Admin Section. |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $pluralTitle; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * URL Prefix of Admin Section. |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $urlPrefix; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The Controller to be used by the Admin. |
||
| 44 | * |
||
| 45 | * This defaults to parent::getController() |
||
| 46 | * if it has been left undefined. |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $controller = \LaravelFlare\Flare\Http\Controllers\AdminController::class; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * The Policy used for the Admin Authorization logic. |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | protected $policy = '\LaravelFlare\Flare\Permissions\AdminPolicy'; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * An array of subclasses of Admin |
||
| 61 | * which allows hierachy in a Module. |
||
| 62 | * |
||
| 63 | * @var array |
||
| 64 | */ |
||
| 65 | protected $subAdmin = []; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * The Admin Default View. |
||
| 69 | * |
||
| 70 | * By Default this is the 404 page |
||
| 71 | * |
||
| 72 | * @var string |
||
| 73 | */ |
||
| 74 | protected $view = 'admin.404'; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Array of View Data to Render. |
||
| 78 | * |
||
| 79 | * @var array |
||
| 80 | */ |
||
| 81 | protected $viewData = []; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Class Suffix used for matching and removing term |
||
| 85 | * from user provided Admin sections. |
||
| 86 | * |
||
| 87 | * @var string |
||
| 88 | */ |
||
| 89 | const CLASS_SUFFIX = 'Admin'; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * __construct. |
||
| 93 | */ |
||
| 94 | public function __construct() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Register the routes for this Admin Section. |
||
| 100 | * |
||
| 101 | * Default routes include, create:, read:, update:, delete: |
||
| 102 | * |
||
| 103 | * Also attempts to load in ModelAdminController |
||
| 104 | * based on the shortName of the class, for |
||
| 105 | * overloading and adding additional routes |
||
| 106 | * |
||
| 107 | * @param \Illuminate\Routing\Router $router |
||
| 108 | */ |
||
| 109 | public function registerRoutes(Router $router) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Register subRoutes for Defined Admin instances. |
||
| 121 | * |
||
| 122 | * @return |
||
| 123 | */ |
||
| 124 | public function registerSubRoutes() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Register an individual route. |
||
| 137 | * |
||
| 138 | * @param string $controller |
||
| 139 | * @param array $parameters |
||
| 140 | * |
||
| 141 | * @return |
||
| 142 | */ |
||
| 143 | public static function registerRoute($controller, $parameters = []) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Stolen Method from 5.2 Illumiante/Routing/Router. |
||
| 152 | * |
||
| 153 | * @param string $controller |
||
| 154 | * @return void |
||
| 155 | */ |
||
| 156 | public static function registerController($controller) |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Returns the Route Paramets. |
||
| 179 | * |
||
| 180 | * @return array |
||
| 181 | */ |
||
| 182 | public function routeParameters() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Returns the Requested Route Action as a |
||
| 192 | * string, namespace is returned by default. |
||
| 193 | * |
||
| 194 | * @param string $key |
||
| 195 | * |
||
| 196 | * @return string|void |
||
| 197 | */ |
||
| 198 | public static function getRequested($key = 'namespace') |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Returns the Controller Class for the current Admin section. |
||
| 215 | * |
||
| 216 | * @return string |
||
| 217 | */ |
||
| 218 | public function getController() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Set the Controller Class for the current Admin section. |
||
| 225 | * |
||
| 226 | * @return string |
||
| 227 | */ |
||
| 228 | public function setController($controller = null) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Returns the Module Admin View. |
||
| 235 | * |
||
| 236 | * @return string |
||
| 237 | */ |
||
| 238 | public function getView() |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Set the Module Admin View. |
||
| 249 | * |
||
| 250 | * @param string $view |
||
| 251 | */ |
||
| 252 | public function setView($view = null) |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Returns the View Data. |
||
| 259 | * |
||
| 260 | * @return array |
||
| 261 | */ |
||
| 262 | public function getViewData() |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Set the View Data. |
||
| 269 | * |
||
| 270 | * @param array $viewData |
||
| 271 | */ |
||
| 272 | public function setViewData($viewData = []) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Menu Items. |
||
| 279 | * |
||
| 280 | * @return array |
||
| 281 | */ |
||
| 282 | public function menuItems() |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Icon of a Admin Section Class. |
||
| 289 | * |
||
| 290 | * @return string |
||
| 291 | */ |
||
| 292 | public function getIcon() |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Set Icon of a Admin Section Class. |
||
| 299 | * |
||
| 300 | * @param string $icon |
||
| 301 | */ |
||
| 302 | public function setIcon($icon = null) |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Shortname of a Admin Section Class. |
||
| 309 | * |
||
| 310 | * @return string |
||
| 311 | */ |
||
| 312 | public static function shortName() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Title of a Admin Section Class. |
||
| 319 | * |
||
| 320 | * @return string |
||
| 321 | */ |
||
| 322 | public function getTitle() |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Set Title of a Admin Section Class. |
||
| 333 | * |
||
| 334 | * @param string $title |
||
| 335 | */ |
||
| 336 | public function setTitle($title = null) |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Plural of the Admin Section Class Title. |
||
| 343 | * |
||
| 344 | * @return string |
||
| 345 | */ |
||
| 346 | public function getPluralTitle() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Set Plural Title. |
||
| 357 | * |
||
| 358 | * @param string $pluralTitle |
||
| 359 | */ |
||
| 360 | public function setPluralTitle($pluralTitle = null) |
||
| 364 | |||
| 365 | /** |
||
| 366 | * URL Prefix to a Admin Section Top Level Page. |
||
| 367 | * |
||
| 368 | * @return string |
||
| 369 | */ |
||
| 370 | public function urlPrefix() |
||
| 378 | |||
| 379 | /** |
||
| 380 | * URL to a Admin Top Level Page. |
||
| 381 | * |
||
| 382 | * @param string $path |
||
| 383 | * |
||
| 384 | * @return string |
||
| 385 | */ |
||
| 386 | public function url($path = '') |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Relative URL to an Admin Top Level Page. |
||
| 393 | * |
||
| 394 | * @param string $path |
||
| 395 | * |
||
| 396 | * @return string |
||
| 397 | */ |
||
| 398 | public function relativeUrl($path = '') |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Retrieves the Current Admin Route URL. |
||
| 405 | * |
||
| 406 | * @param string $path |
||
| 407 | * |
||
| 408 | * @return string |
||
| 409 | */ |
||
| 410 | public function currentUrl($path = '') |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Retrieves the Current Admin Route URL. |
||
| 417 | * |
||
| 418 | * @param string $path |
||
| 419 | * |
||
| 420 | * @return string |
||
| 421 | */ |
||
| 422 | public function relativeCurrentUrl($path) |
||
| 426 | |||
| 427 | /* |
||
| 428 | * Handle dynamic static method calls into the Admin. |
||
| 429 | * |
||
| 430 | * @param string $method |
||
| 431 | * @param array $parameters |
||
| 432 | * |
||
| 433 | * @return mixed |
||
| 434 | */ |
||
| 435 | // public static function __callStatic($method, $parameters) |
||
| 436 | // { |
||
| 437 | // $instance = new static(); |
||
| 438 | |||
| 439 | // return call_user_func_array([$instance, $method], $parameters); |
||
| 440 | // } |
||
| 441 | } |
||
| 442 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.