| Conditions | 10 |
| Paths | 15 |
| Total Lines | 43 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 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 |
||
| 55 | protected function saveForm(FormInterface $form, $entity) |
||
| 56 | { |
||
| 57 | if (!$entity instanceof Customer) { |
||
| 58 | throw new \InvalidArgumentException('Customer expected'); |
||
| 59 | } |
||
| 60 | |||
| 61 | $form->setData($entity); |
||
| 62 | if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) { |
||
| 63 | $form->submit($this->request); |
||
| 64 | |||
| 65 | if ($form->isValid()) { |
||
| 66 | $addressesToSync = []; |
||
| 67 | if ($entity->getId()) { |
||
| 68 | $this->stateHandler->markCustomerForSync($entity); |
||
| 69 | |||
| 70 | if (!$entity->getAddresses()->isEmpty()) { |
||
| 71 | foreach ($entity->getAddresses() as $address) { |
||
| 72 | if (!$address->getOriginId()) { |
||
| 73 | $addressesToSync[] = $address; |
||
| 74 | } else { |
||
| 75 | $this->stateHandler->markAddressForSync($address); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 | $this->saveEntity($entity); |
||
| 81 | |||
| 82 | // Process trigger listen for update, because create will trigger export during import |
||
| 83 | // This will schedule new entity for export |
||
| 84 | if (!$entity->getOriginId()) { |
||
| 85 | $this->scheduleCustomerSyncToMagento($entity); |
||
| 86 | } |
||
| 87 | |||
| 88 | foreach ($addressesToSync as $address) { |
||
| 89 | $this->scheduleAddressSyncToMagento($address); |
||
| 90 | } |
||
| 91 | |||
| 92 | return true; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | return false; |
||
| 97 | } |
||
| 98 | |||
| 129 |