Conditions | 11 |
Paths | 288 |
Total Lines | 39 |
Code Lines | 21 |
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 |
||
89 | public function build(): Invoice |
||
90 | { |
||
91 | $invoice = new Invoice($this->addVat); |
||
92 | $invoice->setCurrency($this->currency); |
||
93 | |||
94 | if (isset($this->invoiceNumber)) { |
||
95 | $invoice->setInvoiceNumber($this->invoiceNumber); |
||
96 | } elseif (isset($this->invoiceNumberGenerator)) { |
||
97 | $invoice->setInvoiceNumber($this->invoiceNumberGenerator->generateNumber()); |
||
98 | } |
||
99 | |||
100 | if (isset($this->freeHandAddress)) { |
||
101 | $invoice->setFreeHandAddress($this->freeHandAddress); |
||
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 | return $invoice; |
||
128 | } |
||
165 |