Conditions | 2 |
Paths | 2 |
Total Lines | 55 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
26 | public function createInvoice(array $invoiceForm): ?Invoice |
||
27 | { |
||
28 | $invoice = new Invoice(); |
||
29 | $invoice |
||
30 | ->setMerchantInfo(new MerchantInfo()) |
||
31 | ->setBillingInfo([(new BillingInfo())]) |
||
32 | ->setNote($invoiceForm['note']) |
||
33 | ->setPaymentTerm(new PaymentTerm()) |
||
34 | ->setShippingInfo(new ShippingInfo()); |
||
35 | |||
36 | $invoice->getMerchantInfo() |
||
37 | ->setEmail($invoiceForm['merchant_email']) |
||
38 | ->setbusinessName($invoiceForm['merchant_business_name']) |
||
39 | ->setAddress(new InvoiceAddress()); |
||
40 | |||
41 | $invoice->getMerchantInfo()->getAddress() |
||
42 | ->setLine1($invoiceForm['merchant_address']) |
||
43 | ->setCity($invoiceForm['merchant_city']) |
||
44 | ->setState($invoiceForm['merchant_state']) |
||
45 | ->setPostalCode($invoiceForm['merchant_zip_code']) |
||
46 | ->setCountryCode($invoiceForm['merchant_country_code']); |
||
47 | |||
48 | $billing = $invoice->getBillingInfo(); |
||
49 | $billing[0]->setLanguage($this->settingsService->getSetting('settings-customer-locale')) |
||
50 | ->setEmail($this->settingsService->getSetting('settings-customer-email')); |
||
51 | $items = []; |
||
52 | $items[0] = new InvoiceItem(); |
||
53 | $items[0] |
||
54 | ->setName($invoiceForm['item_name']) |
||
55 | ->setDescription($invoiceForm['item_description']) |
||
56 | ->setQuantity(1) |
||
57 | ->setUnitPrice(new Currency()); |
||
58 | $items[0]->getUnitPrice() |
||
59 | ->setCurrency($this->settingsService->getSetting('settings-customer-currency')) |
||
60 | ->setValue($invoiceForm['item_amount']); |
||
61 | |||
62 | $tax = new Tax(); |
||
63 | $tax->setPercent($invoiceForm['item_tax_percent']) |
||
64 | ->setName($invoiceForm['item_tax_name']); |
||
65 | $items[0]->setTax($tax); |
||
66 | $invoice->setItems($items); |
||
67 | |||
68 | $invoice->getPaymentTerm() |
||
69 | ->setTermType("NET_10"); |
||
70 | $invoice->setTaxInclusive(true); |
||
71 | $invoice->setLogoUrl('https://www.paypalobjects.com/webstatic/i/logo/rebrand/ppcom.svg'); |
||
72 | |||
73 | try { |
||
74 | $invoice->create($this->apiContext); |
||
75 | } catch (Exception $e) { |
||
76 | $this->logger->error('Error on PayPal::createInvoice = ' . $e->getMessage()); |
||
77 | return null; |
||
78 | } |
||
79 | |||
80 | return $invoice; |
||
81 | } |
||
125 |