Conditions | 60 |
Paths | > 20000 |
Total Lines | 197 |
Code Lines | 103 |
Lines | 145 |
Ratio | 73.6 % |
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 |
||
34 | public static function getData($payment) |
||
35 | { |
||
36 | |||
37 | $data = null; |
||
38 | |||
39 | // reference |
||
40 | if ($payment->getReference() != null) { |
||
41 | $data["reference"] = $payment->getReference(); |
||
42 | } |
||
43 | |||
44 | // sender |
||
45 | View Code Duplication | if ($payment->getSender() != null) { |
|
46 | |||
47 | if ($payment->getSender()->getName() != null) { |
||
48 | $data['senderName'] = $payment->getSender()->getName(); |
||
49 | } |
||
50 | if ($payment->getSender()->getEmail() != null) { |
||
51 | $data['senderEmail'] = $payment->getSender()->getEmail(); |
||
52 | } |
||
53 | |||
54 | // phone |
||
55 | if ($payment->getSender()->getPhone() != null) { |
||
56 | if ($payment->getSender()->getPhone()->getAreaCode() != null) { |
||
57 | $data['senderAreaCode'] = $payment->getSender()->getPhone()->getAreaCode(); |
||
58 | } |
||
59 | if ($payment->getSender()->getPhone()->getNumber() != null) { |
||
60 | $data['senderPhone'] = $payment->getSender()->getPhone()->getNumber(); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | // documents |
||
65 | /*** @var $document PagSeguroDocument */ |
||
66 | if ($payment->getSender()->getDocuments() != null) { |
||
67 | $documents = $payment->getSender()->getDocuments(); |
||
68 | if (is_array($documents) && count($documents) == 1) { |
||
69 | foreach ($documents as $document) { |
||
70 | if (!is_null($document)) { |
||
71 | $data['senderCPF'] = $document->getValue(); |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | if ($payment->getSender()->getIP() != null) { |
||
78 | $data['ip'] = $payment->getSender()->getIP(); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | // currency |
||
83 | if ($payment->getCurrency() != null) { |
||
84 | $data['currency'] = $payment->getCurrency(); |
||
85 | } |
||
86 | |||
87 | // items |
||
88 | $items = $payment->getItems(); |
||
89 | View Code Duplication | if (count($items) > 0) { |
|
90 | |||
91 | $i = 0; |
||
92 | |||
93 | foreach ($items as $key => $value) { |
||
94 | $i++; |
||
95 | if ($items[$key]->getId() != null) { |
||
96 | $data["itemId$i"] = $items[$key]->getId(); |
||
97 | } |
||
98 | if ($items[$key]->getDescription() != null) { |
||
99 | $data["itemDescription$i"] = $items[$key]->getDescription(); |
||
100 | } |
||
101 | if ($items[$key]->getQuantity() != null) { |
||
102 | $data["itemQuantity$i"] = $items[$key]->getQuantity(); |
||
103 | } |
||
104 | if ($items[$key]->getAmount() != null) { |
||
105 | $amount = PagSeguroHelper::decimalFormat($items[$key]->getAmount()); |
||
106 | $data["itemAmount$i"] = $amount; |
||
107 | } |
||
108 | if ($items[$key]->getWeight() != null) { |
||
109 | $data["itemWeight$i"] = $items[$key]->getWeight(); |
||
110 | } |
||
111 | if ($items[$key]->getShippingCost() != null) { |
||
112 | $data["itemShippingCost$i"] = PagSeguroHelper::decimalFormat($items[$key]->getShippingCost()); |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 | |||
117 | // extraAmount |
||
118 | if ($payment->getExtraAmount() != null) { |
||
119 | $data['extraAmount'] = PagSeguroHelper::decimalFormat($payment->getExtraAmount()); |
||
120 | } |
||
121 | |||
122 | // shipping |
||
123 | View Code Duplication | if ($payment->getShipping() != null) { |
|
124 | |||
125 | if ($payment->getShipping()->getType() != null && $payment->getShipping()->getType()->getValue() != null) { |
||
126 | $data['shippingType'] = $payment->getShipping()->getType()->getValue(); |
||
127 | } |
||
128 | |||
129 | if ($payment->getShipping()->getCost() != null && $payment->getShipping()->getCost() != null) { |
||
130 | $data['shippingCost'] = PagSeguroHelper::decimalFormat($payment->getShipping()->getCost()); |
||
131 | } |
||
132 | |||
133 | // address |
||
134 | if ($payment->getShipping()->getAddress() != null) { |
||
135 | if ($payment->getShipping()->getAddress()->getStreet() != null) { |
||
136 | $data['shippingAddressStreet'] = $payment->getShipping()->getAddress()->getStreet(); |
||
137 | } |
||
138 | if ($payment->getShipping()->getAddress()->getNumber() != null) { |
||
139 | $data['shippingAddressNumber'] = $payment->getShipping()->getAddress()->getNumber(); |
||
140 | } |
||
141 | if ($payment->getShipping()->getAddress()->getComplement() != null) { |
||
142 | $data['shippingAddressComplement'] = $payment->getShipping()->getAddress()->getComplement(); |
||
143 | } |
||
144 | if ($payment->getShipping()->getAddress()->getCity() != null) { |
||
145 | $data['shippingAddressCity'] = $payment->getShipping()->getAddress()->getCity(); |
||
146 | } |
||
147 | if ($payment->getShipping()->getAddress()->getState() != null) { |
||
148 | $data['shippingAddressState'] = $payment->getShipping()->getAddress()->getState(); |
||
149 | } |
||
150 | if ($payment->getShipping()->getAddress()->getDistrict() != null) { |
||
151 | $data['shippingAddressDistrict'] = $payment->getShipping()->getAddress()->getDistrict(); |
||
152 | } |
||
153 | if ($payment->getShipping()->getAddress()->getPostalCode() != null) { |
||
154 | $data['shippingAddressPostalCode'] = $payment->getShipping()->getAddress()->getPostalCode(); |
||
155 | } |
||
156 | if ($payment->getShipping()->getAddress()->getCountry() != null) { |
||
157 | $data['shippingAddressCountry'] = $payment->getShipping()->getAddress()->getCountry(); |
||
158 | } |
||
159 | } |
||
160 | } |
||
161 | // maxAge |
||
162 | if ($payment->getMaxAge() != null) { |
||
163 | $data['maxAge'] = $payment->getMaxAge(); |
||
164 | } |
||
165 | // maxUses |
||
166 | if ($payment->getMaxUses() != null) { |
||
167 | $data['maxUses'] = $payment->getMaxUses(); |
||
168 | } |
||
169 | |||
170 | // redirectURL |
||
171 | if ($payment->getRedirectURL() != null) { |
||
172 | $data['redirectURL'] = $payment->getRedirectURL(); |
||
173 | } |
||
174 | |||
175 | // notificationURL |
||
176 | if ($payment->getNotificationURL() != null) { |
||
177 | $data['notificationURL'] = $payment->getNotificationURL(); |
||
178 | } |
||
179 | |||
180 | // metadata |
||
181 | View Code Duplication | if (count($payment->getMetaData()->getItems()) > 0) { |
|
182 | $i = 0; |
||
183 | foreach ($payment->getMetaData()->getItems() as $item) { |
||
184 | if ($item instanceof PagSeguroMetaDataItem) { |
||
185 | if (!PagSeguroHelper::isEmpty($item->getKey()) && !PagSeguroHelper::isEmpty($item->getValue())) { |
||
186 | $i++; |
||
187 | $data['metadataItemKey' . $i] = $item->getKey(); |
||
188 | $data['metadataItemValue' . $i] = $item->getValue(); |
||
189 | |||
190 | if (!PagSeguroHelper::isEmpty($item->getGroup())) { |
||
191 | $data['metadataItemGroup' . $i] = $item->getGroup(); |
||
192 | } |
||
193 | } |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | |||
198 | // paymentMethodConfig |
||
199 | View Code Duplication | if (count($payment->getPaymentMethodConfig()->getConfig()) > 0) { |
|
200 | $i = 0; |
||
201 | foreach ($payment->getPaymentMethodConfig()->getConfig() as $config) { |
||
202 | if ($config instanceof PagSeguroPaymentMethodConfigItem) { |
||
203 | if (!PagSeguroHelper::isEmpty($config->getKey()) && !PagSeguroHelper::isEmpty($config->getValue())) { |
||
204 | $i++; |
||
205 | if (!PagSeguroHelper::isEmpty($config->getGroup())) { |
||
206 | $data['paymentMethodGroup' . $i] = $config->getGroup(); |
||
207 | } |
||
208 | $data['paymentMethodConfigKey' . $i . "_1"] = $config->getKey(); |
||
209 | $data['paymentMethodConfigValue' . $i . "_1"] = $config->getValue(); |
||
210 | } |
||
211 | } |
||
212 | } |
||
213 | } |
||
214 | |||
215 | // parameter |
||
216 | View Code Duplication | if (count($payment->getParameter()->getItems()) > 0) { |
|
217 | foreach ($payment->getParameter()->getItems() as $item) { |
||
218 | if ($item instanceof PagSeguroParameterItem) { |
||
219 | if (!PagSeguroHelper::isEmpty($item->getKey()) && !PagSeguroHelper::isEmpty($item->getValue())) { |
||
220 | if (!PagSeguroHelper::isEmpty($item->getGroup())) { |
||
221 | $data[$item->getKey() . '' . $item->getGroup()] = $item->getValue(); |
||
222 | } else { |
||
223 | $data[$item->getKey()] = $item->getValue(); |
||
224 | } |
||
225 | } |
||
226 | } |
||
227 | } |
||
228 | } |
||
229 | return $data; |
||
230 | } |
||
231 | |||
273 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.