| Conditions | 4 |
| Paths | 9 |
| Total Lines | 57 |
| Code Lines | 36 |
| 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 |
||
| 56 | public function upgrade_300_18010101() |
||
| 57 | { |
||
| 58 | $this->eventDispatcher->notifyEvent('upgrade.customField.start', |
||
| 59 | new Event($this, EventMessage::factory() |
||
| 60 | ->addDescription(__u('Custom fields update')) |
||
| 61 | ->addDescription(__FUNCTION__)) |
||
| 62 | ); |
||
| 63 | |||
| 64 | try { |
||
| 65 | $customFieldTypeService = $this->dic->get(CustomFieldTypeService::class); |
||
| 66 | |||
| 67 | $customFieldType = []; |
||
| 68 | |||
| 69 | foreach ($customFieldTypeService->getAll() as $customFieldTypeData) { |
||
| 70 | $customFieldType[$customFieldTypeData->getName()] = $customFieldTypeData->getId(); |
||
| 71 | } |
||
| 72 | |||
| 73 | $this->transactionAware(function () use ($customFieldType) { |
||
| 74 | $customFieldDefService = $this->dic->get(CustomFieldDefService::class); |
||
| 75 | |||
| 76 | $queryData = new QueryData(); |
||
| 77 | $queryData->setQuery('SELECT id, moduleId, field FROM CustomFieldDefinition WHERE field IS NOT NULL'); |
||
| 78 | |||
| 79 | foreach ($this->db->doSelect($queryData)->getDataAsArray() as $item) { |
||
| 80 | /** @var CustomFieldDefDataOld $data */ |
||
| 81 | $data = Util::unserialize(CustomFieldDefDataOld::class, $item->field, 'SP\DataModel\CustomFieldDefData'); |
||
| 82 | |||
| 83 | $itemData = new CustomFieldDefinitionData(); |
||
| 84 | $itemData->setId($item->id); |
||
| 85 | $itemData->setModuleId($this->moduleMapper((int)$item->moduleId)); |
||
| 86 | $itemData->setName($data->getName()); |
||
| 87 | $itemData->setHelp($data->getHelp()); |
||
| 88 | $itemData->setRequired($data->isRequired()); |
||
|
|
|||
| 89 | $itemData->setShowInList($data->isShowInItemsList()); |
||
| 90 | $itemData->setTypeId($customFieldType[$this->typeMapper((int)$data->getType())]); |
||
| 91 | |||
| 92 | $customFieldDefService->updateRaw($itemData); |
||
| 93 | |||
| 94 | $this->eventDispatcher->notifyEvent('upgrade.customField.process', |
||
| 95 | new Event($this, EventMessage::factory() |
||
| 96 | ->addDescription(__u('Field updated')) |
||
| 97 | ->addDetail(__u('Field'), $data->getName())) |
||
| 98 | ); |
||
| 99 | } |
||
| 100 | }); |
||
| 101 | } catch (\Exception $e) { |
||
| 102 | processException($e); |
||
| 103 | |||
| 104 | $this->eventDispatcher->notifyEvent('exception', new Event($e)); |
||
| 105 | |||
| 106 | throw $e; |
||
| 107 | } |
||
| 108 | |||
| 109 | $this->eventDispatcher->notifyEvent('upgrade.customField.end', |
||
| 110 | new Event($this, EventMessage::factory() |
||
| 111 | ->addDescription(__u('Custom fields update')) |
||
| 112 | ->addDescription(__FUNCTION__)) |
||
| 113 | ); |
||
| 211 | } |