Conditions | 22 |
Paths | 2106 |
Total Lines | 102 |
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 |
||
15 | public function php($data, $allowExistingEmail = false) |
||
16 | { |
||
17 | $this->form->saveDataToSession(); |
||
18 | $valid = parent::php($data); |
||
19 | $uniqueFieldName = Member::get_unique_identifier_field(); |
||
|
|||
20 | $loggedInMember = Member::currentUser(); |
||
21 | $loggedInMemberID = 0; |
||
22 | if (isset($data[$uniqueFieldName]) && $data[$uniqueFieldName]) { |
||
23 | $isShopAdmin = false; |
||
24 | if ($loggedInMember) { |
||
25 | $loggedInMemberID = $loggedInMember->ID; |
||
26 | if ($loggedInMember->IsShopAdmin()) { |
||
27 | $isShopAdmin = true; |
||
28 | } |
||
29 | } |
||
30 | if ($isShopAdmin || $allowExistingEmail) { |
||
31 | //do nothing |
||
32 | } else { |
||
33 | $uniqueFieldValue = Convert::raw2sql($data[$uniqueFieldName]); |
||
34 | //can't be taken |
||
35 | $otherMembersWithSameEmail = Member::get() |
||
36 | ->filter(array($uniqueFieldName => $uniqueFieldValue)) |
||
37 | ->exclude(array('ID' => $loggedInMemberID)); |
||
38 | if ($otherMembersWithSameEmail->count()) { |
||
39 | //we allow existing email |
||
40 | // if we are currently NOT logged in |
||
41 | // in case we place an order! |
||
42 | if ($allowExistingEmail) { |
||
43 | //do nothing |
||
44 | } else { |
||
45 | $message = _t( |
||
46 | 'Account.ALREADYTAKEN', |
||
47 | '{uniqueFieldValue} is already taken by another member. Please log in or use another {uniqueFieldName}.', |
||
48 | array('uniqueFieldValue' => $uniqueFieldValue, 'uniqueFieldName' => $uniqueFieldName) |
||
49 | ); |
||
50 | $this->validationError( |
||
51 | $uniqueFieldName, |
||
52 | $message, |
||
53 | 'required' |
||
54 | ); |
||
55 | $valid = false; |
||
56 | } |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | // check password fields are the same before saving |
||
61 | if (isset($data['PasswordCheck1']) && isset($data['PasswordCheck2'])) { |
||
62 | if ($data['PasswordCheck1'] != $data['PasswordCheck2']) { |
||
63 | $this->validationError( |
||
64 | 'PasswordCheck1', |
||
65 | _t('Account.PASSWORDSERROR', 'Passwords do not match.'), |
||
66 | 'required' |
||
67 | ); |
||
68 | $valid = false; |
||
69 | } |
||
70 | //if you are not logged in, you have not provided a password and the settings require you to be logged in then |
||
71 | //we have a problem |
||
72 | if (!$loggedInMember && !$data['PasswordCheck1'] && EcommerceConfig::get('EcommerceRole', 'must_have_account_to_purchase')) { |
||
73 | $this->validationError( |
||
74 | 'PasswordCheck1', |
||
75 | _t('Account.SELECTPASSWORD', 'Please select a password.'), |
||
76 | 'required' |
||
77 | ); |
||
78 | $valid = false; |
||
79 | } |
||
80 | $letterCount = strlen($data['PasswordCheck1']); |
||
81 | $minLength = Config::inst()->get('ShopAccountForm_Validator', 'minimum_password_length'); |
||
82 | if ($letterCount > 0 && $letterCount < $minLength) { |
||
83 | $this->validationError( |
||
84 | 'PasswordCheck1', |
||
85 | _t('Account.PASSWORDMINIMUMLENGTH', 'Password does not meet minimum standards.'), |
||
86 | 'required' |
||
87 | ); |
||
88 | $valid = false; |
||
89 | } |
||
90 | } |
||
91 | if (isset($data['FirstName'])) { |
||
92 | if (strlen($data['FirstName']) < 2) { |
||
93 | $this->validationError( |
||
94 | 'FirstName', |
||
95 | _t('Account.NOFIRSTNAME', 'Please enter your first name.'), |
||
96 | 'required' |
||
97 | ); |
||
98 | $valid = false; |
||
99 | } |
||
100 | } |
||
101 | if (isset($data['Surname'])) { |
||
102 | if (strlen($data['Surname']) < 2) { |
||
103 | $this->validationError( |
||
104 | 'Surname', |
||
105 | _t('Account.NOSURNAME', 'Please enter your surname.'), |
||
106 | 'required' |
||
107 | ); |
||
108 | $valid = false; |
||
109 | } |
||
110 | } |
||
111 | if (!$valid) { |
||
112 | $this->form->sessionMessage(_t('Account.ERRORINFORM', 'We could not save your details, please check your errors below.'), 'bad'); |
||
113 | } |
||
114 | |||
115 | return $valid; |
||
116 | } |
||
117 | } |
||
118 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.