Conditions | 12 |
Paths | 23 |
Total Lines | 88 |
Code Lines | 55 |
Lines | 4 |
Ratio | 4.55 % |
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 |
||
63 | $this->authenticatorClass = get_class($authenticator); |
||
64 | parent::__construct($link); |
||
65 | } |
||
66 | |||
67 | protected function validateForgotPasswordData(array $data, LostPasswordForm $form) |
||
68 | { |
||
69 | Config::modify()->set(Member::class, 'unique_identifier_field', 'Login'); |
||
70 | |||
71 | // No need to protect against injections, LDAPService will ensure that this is safe |
||
72 | $login = isset($data['Login']) ? trim($data['Login']) : ''; |
||
73 | |||
74 | // Ensure something was provided |
||
75 | if (empty($login)) { |
||
76 | if (Config::inst()->get(LDAPAuthenticator::class, 'allow_email_login') === 'yes') { |
||
77 | $form->sessionMessage( |
||
78 | _t( |
||
79 | 'SilverStripe\\LDAP\\Forms\\LDAPLoginForm.ENTERUSERNAMEOREMAIL', |
||
80 | 'Please enter your username or your email address to get a password reset link.' |
||
81 | ), |
||
82 | 'bad' |
||
83 | ); |
||
84 | } else { |
||
85 | $form->sessionMessage( |
||
86 | _t( |
||
87 | 'SilverStripe\\LDAP\\Forms\\LDAPLoginForm.ENTERUSERNAME', |
||
88 | 'Please enter your username to get a password reset link.' |
||
89 | ), |
||
90 | 'bad' |
||
91 | ); |
||
92 | } |
||
93 | return $this->redirectBack(); |
||
94 | } |
||
95 | |||
96 | // Look up the user and store it |
||
97 | if (Email::is_valid_address($login)) { |
||
98 | if (Config::inst()->get(LDAPAuthenticator::class, 'allow_email_login') != 'yes') { |
||
99 | $form->sessionMessage( |
||
100 | _t( |
||
101 | 'SilverStripe\\LDAP\\Forms\\LDAPLoginForm.USERNAMEINSTEADOFEMAIL', |
||
102 | 'Please enter your username instead of your email to get a password reset link.' |
||
103 | ), |
||
104 | 'bad' |
||
105 | ); |
||
106 | return $this->redirect($this->Link('lostpassword')); |
||
107 | } |
||
108 | $this->ldapUserData = $this->getService()->getUserByEmail($login); |
||
109 | } else { |
||
110 | $this->ldapUserData = $this->getService()->getUserByUsername($login); |
||
111 | } |
||
112 | } |
||
113 | |||
114 | protected function getMemberFromData(array $data, $uniqueIdentifier) |
||
115 | { |
||
116 | $member = Member::get()->filter('GUID', $this->ldapUserData['objectguid'])->limit(1)->first(); |
||
117 | |||
118 | // User haven't been imported yet so do that now |
||
119 | View Code Duplication | if (!$member || !$member->exists()) { |
|
120 | $member = Member::create(); |
||
121 | $member->GUID = $this->ldapUserData['objectguid']; |
||
122 | } |
||
123 | |||
124 | // Update the users from LDAP so we are sure that the email is correct. |
||
125 | // This will also write the Member record. |
||
126 | $this->getService()->updateMemberFromLDAP($member, $this->ldapUserData, false); |
||
127 | |||
128 | return $member; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Factory method for the lost password form |
||
133 | * |
||
134 | * @return Form Returns the lost password form |
||
135 | */ |
||
136 | public function lostPasswordForm() |
||
137 | { |
||
138 | $loginFieldLabel = (Config::inst()->get(LDAPAuthenticator::class, 'allow_email_login') === 'yes') ? |
||
139 | _t('SilverStripe\\LDAP\\Forms\\LDAPLoginForm.USERNAMEOREMAIL', 'Username or email') : |
||
140 | _t('SilverStripe\\LDAP\\Forms\\LDAPLoginForm.USERNAME', 'Username'); |
||
141 | $loginField = TextField::create('Login', $loginFieldLabel); |
||
142 | |||
143 | $action = FormAction::create( |
||
144 | 'forgotPassword', |
||
145 | _t('SilverStripe\\Security\\Security.BUTTONSEND', 'Send me the password reset link') |
||
146 | ); |
||
147 | return LostPasswordForm::create( |
||
148 | $this, |
||
149 | $this->authenticatorClass, |
||
150 | 'LostPasswordForm', |
||
151 | FieldList::create([$loginField]), |
||
223 |
This check marks private properties in classes that are never used. Those properties can be removed.