Conditions | 14 |
Paths | 2304 |
Total Lines | 71 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
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 | if (!isset($invoiceData['bezPolozek'])) { |
||
104 | $invoiceData['bezPolozek'] = false; |
||
105 | } |
||
106 | |||
107 | if (!isset($invoiceData['polozky']) && !$invoiceData['bezPolozek']) { |
||
108 | $invoiceData['bezPolozek'] = true; |
||
109 | if (!array_key_exists('sumCelkZakl', $invoiceData)) { |
||
110 | $scale = pow(1000, 2); |
||
111 | $invoiceData['sumCelkZakl'] = round(mt_rand(10 * $scale, |
||
112 | 9000 * $scale) / $scale, 2); |
||
113 | $invoiceData['castkaMen'] = 0; |
||
114 | $invoiceData['sumCelkem'] = $invoiceData['sumCelkZakl']; |
||
115 | } |
||
116 | } else { |
||
117 | $invoiceData['bezPolozek'] = false; |
||
118 | } |
||
119 | |||
120 | if (!isset($invoiceData['firma'])) { |
||
121 | $adresar = new \FlexiPeeHP\Adresar(); |
||
122 | |||
123 | $adresy = $adresar->getFlexiData(null, |
||
124 | ['typVztahuK' => 'typVztahu.odberatel']); |
||
125 | if (count($adresy)) { |
||
126 | $dodavatel = $adresy[array_rand($adresy)]; |
||
127 | |||
128 | $invoiceData['firma'] = 'code:'.$dodavatel['kod']; |
||
129 | } else { |
||
130 | /** |
||
131 | * Make Some Address First ... |
||
132 | */ |
||
133 | $address = new \FlexiPeeHP\Adresar(); |
||
134 | $address->setDataValue('nazev', \Ease\Sand::randomString()); |
||
135 | $address->setDataValue('poznam', 'Generated Unit Test Customer'); |
||
136 | $address->setDataValue('typVztahuK', 'typVztahu.odberatel'); |
||
137 | $address->insertToFlexiBee(); |
||
138 | $invoiceData['firma'] = $address; |
||
139 | } |
||
140 | } |
||
141 | |||
142 | if (!isset($invoiceData['poznam'])) { |
||
143 | $invoiceData['poznam'] = $this->poznam; |
||
144 | } |
||
145 | |||
146 | $this->object->takeData($invoiceData); |
||
147 | $this->object->insertToFlexiBee(); |
||
148 | |||
149 | $id = $this->object->getLastInsertedId(); |
||
150 | $this->object->loadFromFlexiBee((int) $id); |
||
151 | $this->object->setDataValue('id', $id); |
||
152 | return $id; |
||
153 | } |
||
154 | |||
250 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.