| Conditions | 12 |
| Paths | 1536 |
| Total Lines | 64 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 83 | public function makeInvoice($invoiceData = []) |
||
| 84 | { |
||
| 85 | if (!isset($invoiceData['kod'])) { |
||
| 86 | $invoiceData['kod'] = 'PeeHP'.time(); |
||
| 87 | } |
||
| 88 | if (!isset($invoiceData['varSym'])) { |
||
| 89 | $invoiceData['varSym'] = \Ease\Sand::randomNumber(1000, 99999); |
||
| 90 | } |
||
| 91 | if (!isset($invoiceData['datVyst'])) { |
||
| 92 | $invoiceData['datVyst'] = date("Y-m-d", time() - 60 * 60 * 24); |
||
| 93 | } |
||
| 94 | if (!isset($invoiceData['typDokl'])) { |
||
| 95 | $invoiceData['typDokl'] = 'code:FAKTURA'; |
||
| 96 | } |
||
| 97 | if (!isset($invoiceData['zdrojProSkl'])) { |
||
| 98 | $invoiceData['zdrojProSkl'] = false; |
||
| 99 | } |
||
| 100 | if (!isset($invoiceData['dobropisovano'])) { |
||
| 101 | $invoiceData['dobropisovano'] = false; |
||
| 102 | } |
||
| 103 | |||
| 104 | if (!isset($invoiceData['polozky'])) { |
||
| 105 | $invoiceData['bezPolozek'] = true; |
||
| 106 | } |
||
| 107 | |||
| 108 | if (!isset($invoiceData['sumCelkZakl'])) { |
||
| 109 | $scale = pow(1000, 2); |
||
| 110 | $invoiceData['sumCelkZakl'] = round(mt_rand(10 * $scale, |
||
| 111 | 9000 * $scale) / $scale, 2); |
||
| 112 | } |
||
| 113 | |||
| 114 | if (!isset($invoiceData['firma'])) { |
||
| 115 | $adresar = new \FlexiPeeHP\Adresar(); |
||
| 116 | |||
| 117 | $adresy = $adresar->getFlexiData(null, |
||
| 118 | ['typVztahuK' => 'typVztahu.odberatel']); |
||
| 119 | if (count($adresy)) { |
||
| 120 | $dodavatel = $adresy[array_rand($adresy)]; |
||
| 121 | |||
| 122 | $invoiceData['firma'] = 'code:'.$dodavatel['kod']; |
||
| 123 | } else { |
||
| 124 | /** |
||
| 125 | * Make Some Address First ... |
||
| 126 | */ |
||
| 127 | $address = new \FlexiPeeHP\Adresar(); |
||
| 128 | $address->setDataValue('nazev', \Ease\Sand::randomString()); |
||
| 129 | $address->setDataValue('poznam', 'Generated Unit Test Customrt'); |
||
| 130 | $address->setDataValue('typVztahuK', 'typVztahu.odberatel'); |
||
| 131 | $address->insertToFlexiBee(); |
||
| 132 | $invoiceData['firma'] = $address; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | if (!isset($invoiceData['poznam'])) { |
||
| 137 | $invoiceData['poznam'] = $this->poznam; |
||
| 138 | } |
||
| 139 | |||
| 140 | $this->object->takeData($invoiceData); |
||
| 141 | $this->object->insertToFlexiBee(); |
||
| 142 | |||
| 143 | $id = $this->object->getLastInsertedId(); |
||
| 144 | $this->object->setDataValue('id', $id); |
||
| 145 | return $id; |
||
| 146 | } |
||
| 147 | |||
| 149 |