| Conditions | 2 |
| Paths | 2 |
| Total Lines | 71 |
| 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())->setDate($command->getYear(), 12, 31)->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 | //Damages |
||
| 159 | $this->addDamages($object, $command->getPilot()->getCountForType('damage'), $command->getPilot()->getCountForType('invoiced_damage'), $startYearTimestamp, $endYearTimestamp); |
||
| 160 | |||
| 161 | $this->addOrderDiscount($object, $command->getPilot()->getCountForType('1'), $this->t1->getService(), $command->getYear()); |
||
| 162 | $this->addOrderDiscount($object, $command->getPilot()->getCountForType('2'), $this->t2->getService(), $command->getYear()); |
||
| 163 | $this->addOrderDiscount($object, $command->getPilot()->getCountForType('orga'), $this->tOrganisator, $command->getYear()); |
||
| 164 | $this->addOrderDiscount($object, $command->getPilot()->getCountForType('orga_T6'), $this->tInstructor, $command->getYear()); |
||
| 165 | |||
| 166 | //Additional bonus |
||
| 167 | $this->addAdditionalBonusToOrder($command, $object); |
||
| 168 | |||
| 169 | $object->fetch($id); |
||
| 170 | $object->generateDocument($command->getModelPdf(), $this->langs, $command->isDetailsHidden(), |
||
| 171 | $command->isDescriptionHidden(), $command->isReferenceHidden()); |
||
| 172 | |||
| 173 | // Validate |
||
| 174 | $object->fetch($id); |
||
| 175 | $object->validate($this->user); |
||
| 176 | |||
| 177 | // Generate document |
||
| 178 | $object->fetch($id); |
||
| 179 | $object->generateDocument($command->getModelPdf(), $this->langs, $command->isDetailsHidden(), |
||
| 180 | $command->isDescriptionHidden(), $command->isReferenceHidden()); |
||
| 181 | } |
||
| 182 | |||
| 317 | } |