| Conditions | 11 |
| Paths | 288 |
| Total Lines | 39 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 95 | public function build(): Invoice |
||
| 96 | { |
||
| 97 | $invoice = new Invoice($this->addVat); |
||
| 98 | $invoice->setCurrency($this->currency); |
||
| 99 | |||
| 100 | if (isset($this->deliveryAddress)) { |
||
| 101 | $invoice->setDeliveryAddress($this->deliveryAddress); |
||
| 102 | } |
||
| 103 | |||
| 104 | if (isset($this->billerAddress)) { |
||
| 105 | $invoice->setBillerAddress($this->billerAddress); |
||
| 106 | } |
||
| 107 | |||
| 108 | if (isset($this->createdAt)) { |
||
| 109 | $invoice->setCreatedAt($this->createdAt); |
||
| 110 | } |
||
| 111 | |||
| 112 | if (isset($this->vatNumber)) { |
||
| 113 | $invoice->setVatNumber($this->vatNumber); |
||
| 114 | } |
||
| 115 | |||
| 116 | if (isset($this->paymentDetails)) { |
||
| 117 | $invoice->setPaymentDetails($this->paymentDetails); |
||
| 118 | } |
||
| 119 | |||
| 120 | foreach ($this->items as $item) { |
||
| 121 | if (isset($this->billerAddress) && isset($this->countryRules)) { |
||
| 122 | $this->countryRules->handleRules($item, $this->billerAddress); |
||
| 123 | } |
||
| 124 | $invoice->addItem($item); |
||
| 125 | } |
||
| 126 | |||
| 127 | if (isset($this->invoiceNumber)) { |
||
| 128 | $invoice->setInvoiceNumber($this->invoiceNumber); |
||
| 129 | } elseif (isset($this->invoiceNumberGenerator)) { |
||
| 130 | $invoice->setInvoiceNumber($this->invoiceNumberGenerator->generateNumber($invoice)); |
||
| 131 | } |
||
| 132 | |||
| 133 | return $invoice; |
||
| 134 | } |
||
| 171 |