| Conditions | 31 |
| Paths | 2240 |
| Total Lines | 63 |
| 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 |
||
| 84 | public static function updateZCRMRecordToBean(AbstractZohoDao $dao, ZohoBeanInterface $bean, \ZCRMRecord $record){ |
||
| 85 | $bean->setZCRMRecord($record); |
||
| 86 | $id = $record->getEntityId(); |
||
| 87 | $bean->setZohoId($id); |
||
| 88 | $bean->setCreatedTime(!empty($record->getCreatedTime()) ? \DateTimeImmutable::createFromFormat(\DateTime::ATOM, $record->getCreatedTime()) : null); |
||
| 89 | $bean->setModifiedTime(!empty($record->getModifiedTime()) ? \DateTimeImmutable::createFromFormat(\DateTime::ATOM, $record->getModifiedTime()) : null); |
||
| 90 | $bean->setLastActivityTime(!empty($record->getLastActivityTime()) ? \DateTimeImmutable::createFromFormat(\DateTime::ATOM, $record->getLastActivityTime()) : null); |
||
| 91 | |||
| 92 | if($record->getOwner()) $bean->setOwnerOwnerID($record->getOwner()->getId()); |
||
| 93 | if($record->getOwner()) $bean->setOwnerOwnerName($record->getOwner()->getName()); |
||
| 94 | if($record->getModifiedBy()) $bean->setModifiedByOwnerID($record->getModifiedBy()->getId()); |
||
| 95 | if($record->getModifiedBy()) $bean->setModifiedByOwnerName($record->getModifiedBy()->getName()); |
||
| 96 | if($record->getCreatedBy()) $bean->setCreatedByOwnerID($record->getCreatedBy()->getId()); |
||
| 97 | if($record->getCreatedBy()) $bean->setCreatedByOwnerName($record->getCreatedBy()->getName()); |
||
| 98 | |||
| 99 | $fields = $dao->getFields(); |
||
| 100 | foreach ($fields as $field) { |
||
| 101 | if(!$field->isSystem() && array_key_exists($field->getApiName(), $record->getData())){ |
||
| 102 | $value = $record->getFieldValue($field->getApiName()); |
||
| 103 | $setter = $field->getSetter(); |
||
| 104 | switch ($field->getType()) { |
||
| 105 | case 'date': |
||
| 106 | if ($value && $dateObj = \DateTime::createFromFormat('M/d/Y', $value)) { |
||
| 107 | $value = $dateObj; |
||
| 108 | } elseif ($value && $dateObj = \DateTime::createFromFormat('Y-m-d', $value)) { |
||
| 109 | $value = $dateObj; |
||
| 110 | } elseif ($value && $dateObj = \DateTime::createFromFormat(\DateTime::ATOM, $value)) { |
||
| 111 | $value = $dateObj; |
||
| 112 | } elseif($value !== null) { |
||
| 113 | throw new ZohoCRMORMException('Unable to convert the Date field "' . $field->getName() . "\" into a DateTime PHP object from the the record $id of the module " . $dao->getModule() . '.'); |
||
| 114 | } |
||
| 115 | break; |
||
| 116 | case 'datetime': |
||
| 117 | $value = \DateTime::createFromFormat(\DateTime::ATOM, $value); |
||
| 118 | break; |
||
| 119 | case 'userlookup': |
||
| 120 | case 'lookup': |
||
| 121 | /** |
||
| 122 | * @var $ZCRMRecord \ZCRMRecord |
||
| 123 | */ |
||
| 124 | $ZCRMRecord = $value; |
||
| 125 | $value = $ZCRMRecord? (is_a($ZCRMRecord, 'ZCRMRecord') ? $ZCRMRecord->getEntityId() : $ZCRMRecord):null; |
||
| 126 | break; |
||
| 127 | |||
| 128 | case 'ownerlookup': |
||
| 129 | /** |
||
| 130 | * @var $ZCRMUser \ZCRMUser |
||
| 131 | */ |
||
| 132 | $ZCRMUser = $value; |
||
| 133 | $value = $ZCRMUser?$ZCRMUser->getId():null; |
||
| 134 | break; |
||
| 135 | default: |
||
| 136 | break; |
||
| 137 | } |
||
| 138 | if (($value === false || $value === null) && in_array($field->getType(), ['date', 'datetime', ''])) { |
||
| 139 | $value = null; |
||
| 140 | } |
||
| 141 | $bean->$setter($value); |
||
| 142 | $bean->setDirty($field->getName(), false); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | } |
||
| 147 | } |
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.