| Conditions | 13 |
| Paths | 22 |
| Total Lines | 58 |
| 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 |
||
| 19 | public static function createOrUpdateBeanToZCRMRecord(AbstractZohoDao $dao, ZohoBeanInterface $bean){ |
||
| 20 | |||
| 21 | $record = \ZCRMRecord::getInstance($dao->getModule(), $bean->getZohoId()); |
||
|
|
|||
| 22 | $bean->setZCRMRecord($record); |
||
| 23 | foreach ($dao->getFields() as $field){ |
||
| 24 | if(in_array($field->getName(), EntitiesGeneratorService::$defaultORMSystemFields) || !$bean->isDirty($field->getName())){ |
||
| 25 | continue; |
||
| 26 | } |
||
| 27 | $getter = $field->getGetter(); |
||
| 28 | switch ($field->getType()) { |
||
| 29 | case 'date': |
||
| 30 | /** |
||
| 31 | * @var $date \DateTimeInterface |
||
| 32 | */ |
||
| 33 | $date = $bean->{$getter}(); |
||
| 34 | if($date){ |
||
| 35 | $record->setFieldValue($field->getApiName(), $date->format('Y-m-d')); |
||
| 36 | } |
||
| 37 | break; |
||
| 38 | case 'datetime': |
||
| 39 | /** |
||
| 40 | * @var $date \DateTimeInterface |
||
| 41 | */ |
||
| 42 | $date = $bean->{$getter}(); |
||
| 43 | if($date){ |
||
| 44 | $date->setTimezone(new \DateTimeZone($dao->getZohoClient()->getTimezone())); |
||
| 45 | $record->setFieldValue($field->getApiName(), $date->format(\DateTime::ATOM)); |
||
| 46 | } |
||
| 47 | break; |
||
| 48 | case 'lookup': |
||
| 49 | /** |
||
| 50 | * @var $ZCRMRecord \ZCRMRecord |
||
| 51 | */ |
||
| 52 | $ZCRMRecord = \ZCRMRecord::getInstance($field->getLookupModuleName(), $bean->{$getter}()); |
||
| 53 | $record->setFieldValue($field->getApiName(), $ZCRMRecord); |
||
| 54 | break; |
||
| 55 | case 'ownerlookup': |
||
| 56 | $record->setFieldValue($field->getApiName(), \ZCRMUser::getInstance($bean->{$getter}(), null)); |
||
| 57 | break; |
||
| 58 | case 'multiselectpicklist': |
||
| 59 | if($bean->{$getter}()){ |
||
| 60 | $record->setFieldValue($field->getApiName(), $bean->{$getter}()); |
||
| 61 | } else{ |
||
| 62 | $record->setFieldValue($field->getApiName(),null); |
||
| 63 | } |
||
| 64 | break; |
||
| 65 | default: |
||
| 66 | $record->setFieldValue($field->getApiName(), $bean->{$getter}()); |
||
| 67 | break; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | if(!$record->getOwner()){ |
||
| 71 | $record->setOwner(\ZCRMUser::getInstance($bean->getOwnerOwnerID(),$bean->getOwnerOwnerName())); |
||
| 72 | } else{ |
||
| 73 | $record->getOwner()->setId($bean->getOwnerOwnerID()); |
||
| 74 | $record->getOwner()->setName($bean->getOwnerOwnerName()); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 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.