Conditions | 2 |
Paths | 2 |
Total Lines | 70 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
111 | public function __invoke(CreatePilotYearBillCommand $command) |
||
112 | { |
||
113 | $object = new Facture($this->db); |
||
114 | $object->fetch_thirdparty(); |
||
115 | |||
116 | $object->socid = $this->getCompanyIdFromPilot($command->getPilot()); |
||
117 | $object->type = $command->getBillType(); |
||
118 | $object->number = "provisoire"; |
||
119 | $object->date = (new DateTime())->getTimestamp(); |
||
120 | $object->date_pointoftax = ""; |
||
121 | $object->note_public = $command->getPublicNote(); |
||
122 | $object->note_private = $command->getPrivateNote(); |
||
123 | $object->ref_client = ""; |
||
124 | $object->ref_int = ""; |
||
125 | $object->modelpdf = $command->getModelPdf(); |
||
126 | $object->cond_reglement_id = $command->getReglementCondition(); |
||
127 | $object->mode_reglement_id = $command->getReglementMode(); |
||
128 | $object->fk_account = $command->getBankAccount(); |
||
129 | |||
130 | $id = $object->create($this->user); |
||
131 | |||
132 | if ($id <= 0) { |
||
133 | throw new \InvalidArgumentException('Error while creating order'); |
||
134 | } |
||
135 | |||
136 | $this->localtax1_tx = get_localtax(0, 1, $object->thirdparty); |
||
137 | $this->localtax2_tx = get_localtax(0, 2, $object->thirdparty); |
||
138 | |||
139 | $startYearTimestamp = (new \DateTime())->setDate($command->getYear(), 1, 1)->getTimestamp(); |
||
140 | $endYearTimestamp = (new \DateTime())->setDate($command->getYear(), 12, 31)->getTimestamp(); |
||
141 | |||
142 | //T3 |
||
143 | $this->addOrderLine($object, $this->t3->getService(), $command->getPilot()->getCountForType('3')->getCount(), |
||
144 | $startYearTimestamp, $endYearTimestamp); |
||
145 | |||
146 | //T4 |
||
147 | $this->addOrderLine($object, $this->t4->getService(), $command->getPilot()->getCountForType('4')->getCount(), |
||
148 | $startYearTimestamp, $endYearTimestamp); |
||
149 | |||
150 | //T6 |
||
151 | $this->addOrderLine($object, $this->t6->getService(), $command->getPilot()->getCountForType('6')->getCount(), |
||
152 | $startYearTimestamp, $endYearTimestamp); |
||
153 | |||
154 | //T7 |
||
155 | $this->addOrderLine($object, $this->t7->getService(), $command->getPilot()->getCountForType('7')->getCount(), |
||
156 | $startYearTimestamp, $endYearTimestamp); |
||
157 | |||
158 | $this->addOrderDiscount($object, $command->getPilot()->getCountForType('1'), $this->t1->getService(), $command->getYear()); |
||
159 | $this->addOrderDiscount($object, $command->getPilot()->getCountForType('2'), $this->t2->getService(), $command->getYear()); |
||
160 | $this->addOrderDiscount($object, $command->getPilot()->getCountForType('orga'), $this->tOrganisator, |
||
161 | $command->getYear()); |
||
162 | $this->addOrderDiscount($object, $command->getPilot()->getCountForType('orga_T6'), $this->tInstructor, |
||
163 | $command->getYear()); |
||
164 | |||
165 | //Additional bonus |
||
166 | $this->addAdditionalBonusToOrder($command, $object); |
||
167 | |||
168 | $object->fetch($id); |
||
169 | $object->generateDocument($command->getModelPdf(), $this->langs, $command->isDetailsHidden(), |
||
170 | $command->isDescriptionHidden(), $command->isReferenceHidden()); |
||
171 | |||
172 | // Validate |
||
173 | $object->fetch($id); |
||
174 | $object->validate($this->user); |
||
175 | |||
176 | // Generate document |
||
177 | $object->fetch($id); |
||
178 | $object->generateDocument($command->getModelPdf(), $this->langs, $command->isDetailsHidden(), |
||
179 | $command->isDescriptionHidden(), $command->isReferenceHidden()); |
||
180 | } |
||
181 | |||
290 | } |