Conditions | 6 |
Paths | 8 |
Total Lines | 52 |
Code Lines | 33 |
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 |
||
42 | public function __construct(RequestHandler $controller, $authenticatorClass, $name) |
||
43 | { |
||
44 | |||
45 | parent::__construct($controller, 'LDAPAuthenticator', $name); |
||
46 | |||
47 | if (Config::inst()->get(LDAPAuthenticator::class, 'allow_email_login') === 'yes') { |
||
48 | $loginField = TextField::create( |
||
49 | 'Login', |
||
50 | _t(__CLASS__ . '.USERNAMEOREMAIL', 'Username or email'), |
||
51 | null, |
||
52 | null, |
||
53 | $this |
||
54 | ); |
||
55 | } else { |
||
56 | $loginField = TextField::create('Login', _t(__CLASS__ . '.USERNAME', 'Username'), null, null, $this); |
||
57 | } |
||
58 | |||
59 | $this->Fields()->replaceField('Email', $loginField); |
||
60 | $this->setValidator(new RequiredFields('Login', 'Password')); |
||
61 | if (Security::config()->remember_username) { |
||
62 | $loginField->setValue($this->getSession()->get('SessionForms.MemberLoginForm.Email')); |
||
63 | } else { |
||
64 | // Some browsers won't respect this attribute unless it's added to the form |
||
65 | $this->setAttribute('autocomplete', 'off'); |
||
66 | $loginField->setAttribute('autocomplete', 'off'); |
||
67 | } |
||
68 | |||
69 | // Users can't change passwords unless appropriate a LDAP user with write permissions is |
||
70 | // configured the LDAP connection binding |
||
71 | $this->Actions()->remove($this->Actions()->fieldByName('forgotPassword')); |
||
72 | $allowPasswordChange = Config::inst() |
||
73 | ->get(LDAPService::class, 'allow_password_change'); |
||
74 | if ($allowPasswordChange && $name != 'LostPasswordForm' && !Security::getCurrentUser()) { |
||
75 | $forgotPasswordLink = sprintf( |
||
76 | '<p id="ForgotPassword"><a href="%s">%s</a></p>', |
||
77 | Security::singleton()->Link('lostpassword'), |
||
78 | _t('SilverStripe\\Security\\Member.BUTTONLOSTPASSWORD', "I've lost my password") |
||
79 | ); |
||
80 | $forgotPassword = LiteralField::create('forgotPassword', $forgotPasswordLink); |
||
81 | $this->Actions()->add($forgotPassword); |
||
82 | } |
||
83 | |||
84 | // Focus on the Username field when the page is loaded |
||
85 | Requirements::block('MemberLoginFormFieldFocus'); |
||
86 | $js = <<<JS |
||
87 | (function() { |
||
88 | var el = document.getElementById("Login"); |
||
89 | if(el && el.focus && (typeof jQuery == 'undefined' || jQuery(el).is(':visible'))) el.focus(); |
||
90 | })(); |
||
91 | JS; |
||
92 | Requirements::customScript($js, 'LDAPLoginFormFieldFocus'); |
||
93 | } |
||
94 | |||
106 |