| Conditions | 16 | 
| Paths | 56 | 
| Total Lines | 80 | 
| Code Lines | 60 | 
| 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  | 
            ||
| 17 | public function __construct($controller, $name, $mustCreateAccount = false)  | 
            ||
| 18 |     { | 
            ||
| 19 | $member = Member::currentUser();  | 
            ||
| 20 | $requiredFields = null;  | 
            ||
| 21 |         if ($member && $member->exists()) { | 
            ||
| 22 | $fields = $member->getEcommerceFields(false);  | 
            ||
| 23 | $clearCartAndLogoutLink = ShoppingCart_Controller::clear_cart_and_logout_link();  | 
            ||
| 24 | $loginMessage =  | 
            ||
| 25 | '<span class="customerName">'.Convert::raw2xml($member->FirstName).' '.Convert::raw2xml($member->Surname).'</span>, '  | 
            ||
| 26 |                 .'<a href="'.$clearCartAndLogoutLink.'">'._t('Account.LOGOUT', 'Log out now?'). | 
            ||
| 27 | '</a>';  | 
            ||
| 28 |             if ($loginMessage) { | 
            ||
| 29 | $loginField = new ReadonlyField(  | 
            ||
| 30 | 'LoggedInAsNote',  | 
            ||
| 31 |                     _t('Account.LOGGEDIN', 'You are currently logged in as '), | 
            ||
| 32 | $loginMessage  | 
            ||
| 33 | );  | 
            ||
| 34 | $loginField->dontEscape = true;  | 
            ||
| 35 | $fields->push($loginField);  | 
            ||
| 36 | }  | 
            ||
| 37 | $actions = new FieldList();  | 
            ||
| 38 |             if ($order = ShoppingCart::current_order()) { | 
            ||
| 39 |                 if ($order->getTotalItems()) { | 
            ||
| 40 |                     $actions->push(new FormAction('proceed', _t('Account.SAVE_AND_PROCEED', 'Save changes and proceed to checkout'))); | 
            ||
| 41 |                 } else { | 
            ||
| 42 |                     $actions->push(new FormAction('submit', _t('Account.SAVE', 'Save Changes'))); | 
            ||
| 43 | }  | 
            ||
| 44 | }  | 
            ||
| 45 |         } else { | 
            ||
| 46 |             if (!$member) { | 
            ||
| 47 | $member = new Member();  | 
            ||
| 48 | }  | 
            ||
| 49 | $fields = new FieldList();  | 
            ||
| 50 | $urlParams = $controller->getURLParams();  | 
            ||
| 51 | $backURLLink = Director::baseURL();  | 
            ||
| 52 |             if ($urlParams) { | 
            ||
| 53 |                 foreach ($urlParams as $urlParam) { | 
            ||
| 54 |                     if ($urlParam) { | 
            ||
| 55 | $backURLLink = Controller::join_links($backURLLink, $urlParam);  | 
            ||
| 56 | }  | 
            ||
| 57 | }  | 
            ||
| 58 | }  | 
            ||
| 59 | $backURLLink = urlencode($backURLLink);  | 
            ||
| 60 |             $fields->push(new LiteralField('MemberInfo', '<p class="message good">'._t('OrderForm.MEMBERINFO', 'If you already have an account then please').' <a href="Security/login?BackURL='.$backURLLink.'">'._t('OrderForm.LOGIN', 'log in').'</a>.</p>')); | 
            ||
| 61 | $memberFields = $member->getEcommerceFields($mustCreateAccount);  | 
            ||
| 62 |             if ($memberFields) { | 
            ||
| 63 |                 foreach ($memberFields as $memberField) { | 
            ||
| 64 | $fields->push($memberField);  | 
            ||
| 65 | }  | 
            ||
| 66 | }  | 
            ||
| 67 |             $passwordField = new PasswordField('PasswordCheck1', _t('Account.PASSWORD', 'Password')); | 
            ||
| 68 |             $passwordFieldCheck = new PasswordField('PasswordCheck2', _t('Account.PASSWORDCHECK', 'Password (repeat)')); | 
            ||
| 69 | $fields->push($passwordField);  | 
            ||
| 70 | $fields->push($passwordFieldCheck);  | 
            ||
| 71 | $actions = new FieldList(  | 
            ||
| 72 |                 new FormAction('creatememberandaddtoorder', _t('Account.SAVE', 'Create Account')) | 
            ||
| 73 | );  | 
            ||
| 74 | }  | 
            ||
| 75 | |||
| 76 | $requiredFields = ShopAccountForm_Validator::create($member->getEcommerceRequiredFields());  | 
            ||
| 77 | parent::__construct($controller, $name, $fields, $actions, $requiredFields);  | 
            ||
| 78 |         $this->setAttribute('autocomplete', 'off'); | 
            ||
| 79 | //extensions need to be set after __construct  | 
            ||
| 80 | //extension point  | 
            ||
| 81 |         $this->extend('updateFields', $fields); | 
            ||
| 82 | $this->setFields($fields);  | 
            ||
| 83 |         $this->extend('updateActions', $actions); | 
            ||
| 84 | $this->setActions($actions);  | 
            ||
| 85 |         $this->extend('updateValidator', $requiredFields); | 
            ||
| 86 | $this->setValidator($requiredFields);  | 
            ||
| 87 | |||
| 88 |         if ($member) { | 
            ||
| 89 | $this->loadDataFrom($member);  | 
            ||
| 90 | }  | 
            ||
| 91 |         $oldData = Session::get("FormInfo.{$this->FormName()}.data"); | 
            ||
| 92 |         if ($oldData && (is_array($oldData) || is_object($oldData))) { | 
            ||
| 93 | $this->loadDataFrom($oldData);  | 
            ||
| 94 | }  | 
            ||
| 95 |         $this->extend('updateShopAccountForm', $this); | 
            ||
| 96 | }  | 
            ||
| 97 | |||
| 204 | 
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.