| Conditions | 10 |
| Paths | 8 |
| Total Lines | 39 |
| 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 |
||
| 19 | public function onBeforeSecurityLogin() |
||
| 20 | { |
||
| 21 | if (Authenticator::get_default_authenticator() != 'SAMLAuthenticator') { |
||
| 22 | return; |
||
| 23 | } |
||
| 24 | |||
| 25 | // by going to the URL Security/login?showloginform=1 we bypass the auto sign on |
||
| 26 | if ($this->owner->request->getVar('showloginform') == 1) { |
||
| 27 | return; |
||
| 28 | } |
||
| 29 | |||
| 30 | // if member is already logged in, don't auto-sign-on, this is most likely because |
||
| 31 | // of unsufficient permissions. |
||
| 32 | $member = Member::currentUser(); |
||
| 33 | if ($member && $member->exists()) { |
||
| 34 | return; |
||
| 35 | } |
||
| 36 | |||
| 37 | // if there are form messages, don't auto-sign-on, this is most likely because of |
||
| 38 | // login errors / failures or other notices. |
||
| 39 | if (Session::get('FormInfo')) { |
||
| 40 | // since FormInfo can be a "nulled" array, we have to check |
||
| 41 | foreach (Session::get('FormInfo') as $form => $info) { |
||
| 42 | foreach ($info as $name => $value) { |
||
| 43 | if ($value !== null) { |
||
| 44 | return; |
||
| 45 | } |
||
| 46 | } |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | $backURL = Session::get('BackURL'); |
||
| 51 | if ($this->owner->request->getVar('BackURL')) { |
||
| 52 | $backURL = $this->owner->request->getVar('BackURL'); |
||
| 53 | } |
||
| 54 | |||
| 55 | $authenticator = Injector::inst()->create('SAMLAuthenticator'); |
||
| 56 | $authenticator->authenticate(["BackURL" => $backURL]); |
||
| 57 | } |
||
| 58 | } |
||
| 59 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.