Conditions | 15 |
Paths | 24 |
Total Lines | 70 |
Code Lines | 61 |
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 |
||
60 | public function getFieldInstanceByName($name) |
||
61 | { |
||
62 | $moduleName = $this->getModule()->getName(true); |
||
63 | $fieldsLabel = $this->getEditFields(); |
||
64 | $params = ['uitype' => 1, 'column' => $name, 'name' => $name, 'label' => $fieldsLabel[$name], 'displaytype' => 1, 'typeofdata' => 'V~M', 'presence' => 0, 'isEditableReadOnly' => false]; |
||
65 | switch ($name) { |
||
66 | case 'crmid': |
||
67 | $params['uitype'] = 10; |
||
68 | $params['referenceList'] = ['Contacts']; |
||
69 | $params['fieldparams'] = [ |
||
70 | 'searchParams' => '[[["email","ny",""]]]', |
||
71 | ]; |
||
72 | break; |
||
73 | case 'istorage': |
||
74 | $params['uitype'] = 10; |
||
75 | $params['referenceList'] = ['IStorages']; |
||
76 | $params['typeofdata'] = 'V~O'; |
||
77 | break; |
||
78 | case 'status': |
||
79 | $params['uitype'] = 16; |
||
80 | $params['picklistValues'] = [1 => \App\Language::translate('FL_ACTIVE'), 0 => \App\Language::translate('FL_INACTIVE')]; |
||
81 | break; |
||
82 | case 'server_id': |
||
83 | $servers = Settings_WebserviceApps_Module_Model::getActiveServers($this->getModule()->typeApi); |
||
84 | $params['uitype'] = 16; |
||
85 | $params['picklistValues'] = []; |
||
86 | foreach ($servers as $key => $value) { |
||
87 | $params['picklistValues'][$key] = $value['name']; |
||
88 | } |
||
89 | break; |
||
90 | case 'type': |
||
91 | $params['uitype'] = 16; |
||
92 | $params['picklistValues'] = []; |
||
93 | foreach ($this->getTypeValues() as $key => $value) { |
||
|
|||
94 | $params['picklistValues'][$key] = \App\Language::translate($value, $moduleName); |
||
95 | } |
||
96 | break; |
||
97 | case 'language': |
||
98 | $params['typeofdata'] = 'V~O'; |
||
99 | $params['uitype'] = 32; |
||
100 | $params['picklistValues'] = \App\Language::getAll(); |
||
101 | break; |
||
102 | case 'user_id': |
||
103 | $params['uitype'] = 16; |
||
104 | $params['picklistValues'] = \App\Fields\Owner::getInstance($moduleName)->getAccessibleUsers('', 'owner'); |
||
105 | break; |
||
106 | case 'login_method': |
||
107 | $params['uitype'] = 16; |
||
108 | $params['picklistValues'] = [ |
||
109 | 'PLL_PASSWORD' => \App\Language::translate('PLL_PASSWORD', 'Users'), |
||
110 | 'PLL_PASSWORD_2FA' => \App\Language::translate('PLL_PASSWORD_2FA', 'Users'), |
||
111 | ]; |
||
112 | break; |
||
113 | case 'authy_methods': |
||
114 | $params['uitype'] = 16; |
||
115 | $params['typeofdata'] = 'V~O'; |
||
116 | $params['picklistValues'] = [ |
||
117 | '-' => \App\Language::translate('LBL_NONE'), |
||
118 | 'PLL_AUTHY_TOTP' => \App\Language::translate('PLL_AUTHY_TOTP', 'Users'), |
||
119 | ]; |
||
120 | break; |
||
121 | case 'password': |
||
122 | $params['typeofdata'] = 'P~M'; |
||
123 | if ($this->has('id')) { |
||
124 | $params = null; |
||
125 | } |
||
126 | break; |
||
127 | default: break; |
||
128 | } |
||
129 | return $params ? Settings_Vtiger_Field_Model::init($moduleName, $params) : null; |
||
130 | } |
||
190 |