| Conditions | 9 |
| Paths | 50 |
| Total Lines | 55 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 30 | public function __construct($controller, $name, $fields = null, $actions = null) |
||
| 31 | { |
||
| 32 | parent::__construct($controller, $name, $fields, $actions); |
||
| 33 | |||
| 34 | // Obtain the Member object. If the user got this far, they must have already been synced. |
||
| 35 | $member = Security::getCurrentUser(); |
||
| 36 | if (!$member) { |
||
|
|
|||
| 37 | if ($this->getSession()->get('AutoLoginHash')) { |
||
| 38 | $member = Member::member_from_autologinhash($this->getSession()->get('AutoLoginHash')); |
||
| 39 | } |
||
| 40 | |||
| 41 | // The user is not logged in and no valid auto login hash is available |
||
| 42 | if (!$member) { |
||
| 43 | $this->getSession()->clear('AutoLoginHash'); |
||
| 44 | return $this->controller->redirect($this->controller->Link('login')); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | $data = Injector::inst() |
||
| 49 | ->get(LDAPService::class) |
||
| 50 | ->getUserByGUID($member->GUID, ['samaccountname']); |
||
| 51 | |||
| 52 | $emailField = null; |
||
| 53 | $usernameField = null; |
||
| 54 | if (Config::inst()->get( |
||
| 55 | LDAPAuthenticator::class, |
||
| 56 | 'allow_email_login' |
||
| 57 | ) === 'yes' |
||
| 58 | && !empty($member->Email) |
||
| 59 | ) { |
||
| 60 | $emailField = TextField::create( |
||
| 61 | 'Email', |
||
| 62 | _t(__CLASS__ . '.USERNAMEOREMAIL', 'Email'), |
||
| 63 | $member->Email, |
||
| 64 | null, |
||
| 65 | $this |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | if (!empty($data['samaccountname'])) { |
||
| 69 | $usernameField = TextField::create( |
||
| 70 | 'Username', |
||
| 71 | _t(__CLASS__ . '.USERNAME', 'Username'), |
||
| 72 | $data['samaccountname'], |
||
| 73 | null, |
||
| 74 | $this |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($emailField) { |
||
| 79 | $emailFieldReadonly = $emailField->performDisabledTransformation(); |
||
| 80 | $this->Fields()->unshift($emailFieldReadonly); |
||
| 81 | } |
||
| 82 | if ($usernameField) { |
||
| 83 | $usernameFieldReadonly = $usernameField->performDisabledTransformation(); |
||
| 84 | $this->Fields()->unshift($usernameFieldReadonly); |
||
| 85 | } |
||
| 88 |