| Conditions | 9 | 
| Paths | 10 | 
| Total Lines | 75 | 
| Code Lines | 42 | 
| 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  | 
            ||
| 51 | public function acs()  | 
            ||
| 52 |     { | 
            ||
| 53 | $auth = Injector::inst()->get(SAMLHelper::class)->getSAMLAuth();  | 
            ||
| 54 | $auth->processResponse();  | 
            ||
| 55 | |||
| 56 | $error = $auth->getLastErrorReason();  | 
            ||
| 57 |         if (!empty($error)) { | 
            ||
| 58 | $this->getLogger()->error($error);  | 
            ||
| 59 | |||
| 60 |             $this->getForm()->sessionMessage("Authentication error: '{$error}'", 'bad'); | 
            ||
| 61 | $this->getRequest()->getSession()->save($this->getRequest());  | 
            ||
| 62 | return $this->getRedirect();  | 
            ||
| 63 | }  | 
            ||
| 64 | |||
| 65 |         if (!$auth->isAuthenticated()) { | 
            ||
| 66 |             $this->getForm()->sessionMessage(_t('SilverStripe\\Security\\Member.ERRORWRONGCRED'), 'bad'); | 
            ||
| 67 | $this->getRequest()->getSession()->save($this->getRequest());  | 
            ||
| 68 | return $this->getRedirect();  | 
            ||
| 69 | }  | 
            ||
| 70 | |||
| 71 | $decodedNameId = base64_decode($auth->getNameId());  | 
            ||
| 72 | // check that the NameID is a binary string (which signals that it is a guid  | 
            ||
| 73 |         if (ctype_print($decodedNameId)) { | 
            ||
| 74 |             $this->getForm()->sessionMessage('Name ID provided by IdP is not a binary GUID.', 'bad'); | 
            ||
| 75 | $this->getRequest()->getSession()->save($this->getRequest());  | 
            ||
| 76 | return $this->getRedirect();  | 
            ||
| 77 | }  | 
            ||
| 78 | |||
| 79 | // transform the NameId to guid  | 
            ||
| 80 | $helper = SAMLHelper::singleton();  | 
            ||
| 81 | $guid = $helper->binToStrGuid($decodedNameId);  | 
            ||
| 82 |         if (!$helper->validGuid($guid)) { | 
            ||
| 83 |             $errorMessage = "Not a valid GUID '{$guid}' recieved from server."; | 
            ||
| 84 | $this->getLogger()->error($errorMessage);  | 
            ||
| 85 | $this->getForm()->sessionMessage($errorMessage, 'bad');  | 
            ||
| 86 | $this->getRequest()->getSession()->save($this->getRequest());  | 
            ||
| 87 | return $this->getRedirect();  | 
            ||
| 88 | }  | 
            ||
| 89 | |||
| 90 | // Write a rudimentary member with basic fields on every login, so that we at least have something  | 
            ||
| 91 | // if LDAP synchronisation fails.  | 
            ||
| 92 |         $member = Member::get()->filter('GUID', $guid)->limit(1)->first(); | 
            ||
| 93 |         if (!($member && $member->exists())) { | 
            ||
| 94 | $member = new Member();  | 
            ||
| 95 | $member->GUID = $guid;  | 
            ||
| 96 | }  | 
            ||
| 97 | |||
| 98 | $attributes = $auth->getAttributes();  | 
            ||
| 99 | |||
| 100 |         foreach ($member->config()->claims_field_mappings as $claim => $field) { | 
            ||
| 101 |             if (!isset($attributes[$claim][0])) { | 
            ||
| 102 | $this->getLogger()->warning(  | 
            ||
| 103 | sprintf(  | 
            ||
| 104 | 'Claim rule \'%s\' configured in LDAPMember.claims_field_mappings, ' .  | 
            ||
| 105 | 'but wasn\'t passed through. Please check IdP claim rules.',  | 
            ||
| 106 | $claim  | 
            ||
| 107 | )  | 
            ||
| 108 | );  | 
            ||
| 109 | |||
| 110 | continue;  | 
            ||
| 111 | }  | 
            ||
| 112 | |||
| 113 | $member->$field = $attributes[$claim][0];  | 
            ||
| 114 | }  | 
            ||
| 115 | |||
| 116 | $member->SAMLSessionIndex = $auth->getSessionIndex();  | 
            ||
| 117 | |||
| 118 | // This will trigger LDAP update through LDAPMemberExtension::memberLoggedIn.  | 
            ||
| 119 | // The LDAP update will also write the Member record. We shouldn't write before  | 
            ||
| 120 | // calling this, as any onAfterWrite hooks that attempt to update LDAP won't  | 
            ||
| 121 | // have the Username field available yet for new Member records, and fail.  | 
            ||
| 122 | // Both SAML and LDAP identify Members by the GUID field.  | 
            ||
| 123 | Security::setCurrentUser($member);  | 
            ||
| 124 | |||
| 125 | return $this->getRedirect();  | 
            ||
| 126 | }  | 
            ||
| 201 | 
This check marks private properties in classes that are never used. Those properties can be removed.