Conditions | 5 |
Paths | 5 |
Total Lines | 56 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
97 | public function getData() |
||
98 | { |
||
99 | $this->validate('sessionToken', 'returnUrl'); |
||
100 | |||
101 | // Required values |
||
102 | $data = [ |
||
103 | 'session_token' => $this->getSessionToken(), |
||
104 | 'success_redirect_url' => $this->getReturnUrl(), |
||
105 | ]; |
||
106 | |||
107 | // Optional values |
||
108 | $prefilledBankAccount = [ |
||
109 | 'account_type' => $this->getAccountType(), |
||
110 | ]; |
||
111 | $prefilledCustomer = [ |
||
112 | 'language' => $this->getLanguage(), |
||
113 | // @todo validate against country? |
||
114 | 'danish_identity_number' => $this->getDanishIdentityNumber(), |
||
115 | // @todo validate against country? |
||
116 | 'swedish_identity_number' => $this->getSwedishIdentityNumber(), |
||
117 | ]; |
||
118 | $card = $this->getCard(); |
||
119 | if ($card) { |
||
|
|||
120 | $prefilledCustomer += [ |
||
121 | 'address_line1' => $card->getAddress1(), |
||
122 | 'address_line2' => $card->getAddress2(), |
||
123 | 'address_line3' => $card->getAddress3(), |
||
124 | 'city' => $card->getCity(), |
||
125 | 'postal_code' => $card->getPostcode(), |
||
126 | 'region' => $card->getState(), |
||
127 | // ISO 3166-1 alpha-2 code |
||
128 | 'country_code' => $card->getCountry(), |
||
129 | 'email' => $card->getEmail(), |
||
130 | 'family_name' => $card->getLastName(), |
||
131 | 'given_name' => $card->getFirstName(), |
||
132 | // phone number is for New Zealand customers only |
||
133 | 'phone_number' => $card->getCountry() == 'NZ' ? $card->getPhone() : null, |
||
134 | ]; |
||
135 | if ($card->getLastName() == null && $card->getLastName() == null) { |
||
136 | $prefilledCustomer['company_name'] = $card->getCompany(); |
||
137 | } |
||
138 | } |
||
139 | $links = [ |
||
140 | 'creditor' => $this->getCreditorId(), |
||
141 | ]; |
||
142 | $data += array_filter([ |
||
143 | 'description' => $this->getDescription(), |
||
144 | // key-value store, ends up as native JSON rather than encoded string |
||
145 | 'metadata' => $this->getMetaData(), |
||
146 | 'prefilled_bank_account' => array_filter($prefilledBankAccount), |
||
147 | 'prefilled_customer' => array_filter($prefilledCustomer), |
||
148 | 'scheme' => $this->getScheme(), |
||
149 | 'links' => array_filter($links), |
||
150 | ]); |
||
151 | |||
152 | return $data; |
||
153 | } |
||
172 |