| Conditions | 21 |
| Paths | 40 |
| Total Lines | 268 |
| Code Lines | 241 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 141 | public function getFieldInstanceByName($name) |
||
| 142 | { |
||
| 143 | $params = []; |
||
| 144 | switch ($name) { |
||
| 145 | case 'name': |
||
| 146 | $params = [ |
||
| 147 | 'name' => $name, |
||
| 148 | 'label' => 'FL_SUBJECT', |
||
| 149 | 'uitype' => 1, |
||
| 150 | 'typeofdata' => 'V~M', |
||
| 151 | 'maximumlength' => '50', |
||
| 152 | 'purifyType' => \App\Purifier::TEXT, |
||
| 153 | 'blockLabel' => 'BL_BASE', |
||
| 154 | 'table' => $this->getBaseTable() |
||
| 155 | ]; |
||
| 156 | break; |
||
| 157 | case 'auth_method': |
||
| 158 | $params = [ |
||
| 159 | 'name' => $name, |
||
| 160 | 'label' => 'FL_AUTH_METHOD', |
||
| 161 | 'uitype' => 16, |
||
| 162 | 'typeofdata' => 'V~M', |
||
| 163 | 'maximumlength' => '50', |
||
| 164 | 'purifyType' => \App\Purifier::ALNUM, |
||
| 165 | 'blockLabel' => 'BL_BASE', |
||
| 166 | 'table' => $this->getBaseTable(), |
||
| 167 | 'defaultvalue' => 'basic', |
||
| 168 | 'picklistValues' => [ |
||
| 169 | 'basic' => \App\Language::translate('LBL_BASIC_AUTH', $this->getName(true)), |
||
| 170 | 'oauth2' => \App\Language::translate('LBL_OAUTH2', $this->getName(true)) |
||
| 171 | ] |
||
| 172 | ]; |
||
| 173 | break; |
||
| 174 | case 'status': |
||
| 175 | $params = [ |
||
| 176 | 'name' => $name, |
||
| 177 | 'label' => 'FL_ACTIVE', |
||
| 178 | 'uitype' => 56, |
||
| 179 | 'typeofdata' => 'C~O', |
||
| 180 | 'maximumlength' => '1', |
||
| 181 | 'purifyType' => \App\Purifier::BOOL, |
||
| 182 | 'blockLabel' => 'BL_BASE', |
||
| 183 | 'table' => $this->getBaseTable() |
||
| 184 | ]; |
||
| 185 | break; |
||
| 186 | case 'imap_host': |
||
| 187 | $params = [ |
||
| 188 | 'name' => $name, |
||
| 189 | 'label' => 'FL_IMAP_HOST', |
||
| 190 | 'uitype' => 17, |
||
| 191 | 'typeofdata' => 'C~O', |
||
| 192 | 'maximumlength' => '128', |
||
| 193 | 'tooltip' => 'LBL_IMAP_HOST_DESC', |
||
| 194 | 'purifyType' => \App\Purifier::URL, |
||
| 195 | 'blockLabel' => 'BL_IMAP', |
||
| 196 | 'table' => $this->getBaseTable() |
||
| 197 | ]; |
||
| 198 | break; |
||
| 199 | case 'smtp_host': |
||
| 200 | $params = [ |
||
| 201 | 'name' => $name, |
||
| 202 | 'label' => 'FL_SMTP_HOST', |
||
| 203 | 'uitype' => 17, |
||
| 204 | 'typeofdata' => 'V~O', |
||
| 205 | 'maximumlength' => '128', |
||
| 206 | 'tooltip' => 'LBL_SMTP_HOST_DESC', |
||
| 207 | 'purifyType' => \App\Purifier::URL, |
||
| 208 | 'blockLabel' => 'BL_SMTP', |
||
| 209 | 'table' => $this->getBaseTable() |
||
| 210 | ]; |
||
| 211 | break; |
||
| 212 | case 'imap_port': |
||
| 213 | $params = [ |
||
| 214 | 'name' => $name, |
||
| 215 | 'label' => 'FL_IMAP_PORT', |
||
| 216 | 'uitype' => 7, |
||
| 217 | 'typeofdata' => 'I~O', |
||
| 218 | 'maximumlength' => '0,65535', |
||
| 219 | 'purifyType' => \App\Purifier::INTEGER, |
||
| 220 | 'blockLabel' => 'BL_IMAP', |
||
| 221 | 'table' => $this->getBaseTable() |
||
| 222 | ]; |
||
| 223 | break; |
||
| 224 | case 'smtp_port': |
||
| 225 | $params = [ |
||
| 226 | 'name' => $name, |
||
| 227 | 'label' => 'FL_SMTP_PORT', |
||
| 228 | 'uitype' => 7, |
||
| 229 | 'typeofdata' => 'I~O', |
||
| 230 | 'maximumlength' => '0,65535', |
||
| 231 | 'purifyType' => \App\Purifier::INTEGER, |
||
| 232 | 'blockLabel' => 'BL_SMTP', |
||
| 233 | 'table' => $this->getBaseTable() |
||
| 234 | ]; |
||
| 235 | break; |
||
| 236 | case 'imap_encrypt': |
||
| 237 | $params = [ |
||
| 238 | 'name' => $name, |
||
| 239 | 'label' => 'FL_IMAP_ENCRYPT', |
||
| 240 | 'uitype' => 16, |
||
| 241 | 'typeofdata' => 'V~O', |
||
| 242 | 'maximumlength' => '5', |
||
| 243 | 'purifyType' => \App\Purifier::STANDARD, |
||
| 244 | 'blockLabel' => 'BL_IMAP', |
||
| 245 | 'defaultvalue' => '', |
||
| 246 | 'table' => $this->getBaseTable() |
||
| 247 | ]; |
||
| 248 | $params['picklistValues'] = [ |
||
| 249 | 'ssl' => \App\Language::translate('ssl', $this->getName(true)), |
||
| 250 | 'tls' => \App\Language::translate('tls', $this->getName(true)) |
||
| 251 | ]; |
||
| 252 | break; |
||
| 253 | case 'smtp_encrypt': |
||
| 254 | $params = [ |
||
| 255 | 'name' => $name, |
||
| 256 | 'label' => 'FL_SMTP_ENCRYPT', |
||
| 257 | 'uitype' => 16, |
||
| 258 | 'typeofdata' => 'V~O', |
||
| 259 | 'maximumlength' => '5', |
||
| 260 | 'purifyType' => \App\Purifier::STANDARD, |
||
| 261 | 'blockLabel' => 'BL_SMTP', |
||
| 262 | 'defaultvalue' => '', |
||
| 263 | 'table' => $this->getBaseTable() |
||
| 264 | ]; |
||
| 265 | $params['picklistValues'] = [ |
||
| 266 | 'ssl' => \App\Language::translate('ssl', $this->getName(true)), |
||
| 267 | 'tls' => \App\Language::translate('tls', $this->getName(true)) |
||
| 268 | ]; |
||
| 269 | break; |
||
| 270 | case 'session_lifetime': |
||
| 271 | $params = [ |
||
| 272 | 'name' => $name, |
||
| 273 | 'label' => 'FL_SESSION_LIFETIME', |
||
| 274 | 'uitype' => 7, |
||
| 275 | 'typeofdata' => 'I~M', |
||
| 276 | 'maximumlength' => '0,65535', |
||
| 277 | 'purifyType' => \App\Purifier::BOOL, |
||
| 278 | 'blockLabel' => 'BL_OTHER', |
||
| 279 | 'table' => $this->getBaseTable() |
||
| 280 | ]; |
||
| 281 | break; |
||
| 282 | case 'validate_cert': |
||
| 283 | $params = [ |
||
| 284 | 'name' => $name, |
||
| 285 | 'label' => 'FL_VALIDATE_CERT', |
||
| 286 | 'uitype' => 56, |
||
| 287 | 'typeofdata' => 'C~O', |
||
| 288 | 'maximumlength' => '1', |
||
| 289 | 'purifyType' => \App\Purifier::BOOL, |
||
| 290 | 'blockLabel' => 'BL_BASE', |
||
| 291 | 'table' => $this->getBaseTable() |
||
| 292 | ]; |
||
| 293 | break; |
||
| 294 | case 'spellcheck': |
||
| 295 | $params = [ |
||
| 296 | 'name' => $name, |
||
| 297 | 'label' => 'FL_SPELL_CHECK', |
||
| 298 | 'uitype' => 56, |
||
| 299 | 'typeofdata' => 'C~O', |
||
| 300 | 'maximumlength' => '1', |
||
| 301 | 'purifyType' => \App\Purifier::BOOL, |
||
| 302 | 'blockLabel' => 'BL_OTHER', |
||
| 303 | 'table' => $this->getBaseTable() |
||
| 304 | ]; |
||
| 305 | break; |
||
| 306 | case 'ip_check': |
||
| 307 | $params = [ |
||
| 308 | 'name' => $name, |
||
| 309 | 'label' => 'FL_IP_CHECK', |
||
| 310 | 'uitype' => 56, |
||
| 311 | 'typeofdata' => 'C~O', |
||
| 312 | 'maximumlength' => '1', |
||
| 313 | 'purifyType' => \App\Purifier::BOOL, |
||
| 314 | 'blockLabel' => 'BL_OTHER', |
||
| 315 | 'table' => $this->getBaseTable() |
||
| 316 | ]; |
||
| 317 | break; |
||
| 318 | case 'identities_level': |
||
| 319 | $params = [ |
||
| 320 | 'name' => $name, |
||
| 321 | 'label' => 'FL_IDENTITIES_LEVEL', |
||
| 322 | 'uitype' => 16, |
||
| 323 | 'typeofdata' => 'V~M', |
||
| 324 | 'maximumlength' => '1', |
||
| 325 | 'purifyType' => \App\Purifier::INTEGER, |
||
| 326 | 'blockLabel' => 'BL_OTHER', |
||
| 327 | 'defaultvalue' => 0, |
||
| 328 | 'table' => $this->getBaseTable() |
||
| 329 | ]; |
||
| 330 | $params['picklistValues'] = [ |
||
| 331 | 0 => \App\Language::translate('identities_level_0', $this->getName(true)), |
||
| 332 | 1 => \App\Language::translate('identities_level_1', $this->getName(true)), |
||
| 333 | 2 => \App\Language::translate('identities_level_2', $this->getName(true)), |
||
| 334 | 3 => \App\Language::translate('identities_level_3', $this->getName(true)), |
||
| 335 | 4 => \App\Language::translate('identities_level_4', $this->getName(true)) |
||
| 336 | ]; |
||
| 337 | break; |
||
| 338 | case 'visible': |
||
| 339 | $params = [ |
||
| 340 | 'name' => $name, |
||
| 341 | 'label' => 'FL_VISIBLE', |
||
| 342 | 'uitype' => 56, |
||
| 343 | 'typeofdata' => 'C~O', |
||
| 344 | 'maximumlength' => '1', |
||
| 345 | 'purifyType' => \App\Purifier::BOOL, |
||
| 346 | 'blockLabel' => 'BL_BASE', |
||
| 347 | 'table' => $this->getBaseTable() |
||
| 348 | ]; |
||
| 349 | break; |
||
| 350 | case 'oauth_provider': |
||
| 351 | $params = [ |
||
| 352 | 'name' => $name, |
||
| 353 | 'label' => 'FL_OAUTH_PROVIDER', |
||
| 354 | 'uitype' => 16, |
||
| 355 | 'typeofdata' => 'V~M', |
||
| 356 | 'maximumlength' => '50', |
||
| 357 | 'purifyType' => \App\Purifier::INTEGER, |
||
| 358 | 'blockLabel' => 'BL_BASE', |
||
| 359 | 'defaultvalue' => '', |
||
| 360 | 'table' => $this->getBaseTable(), |
||
| 361 | 'picklistValues' => array_map(fn ($provider) => \App\Language::translate($provider->getLabel(), $this->getName(true)), \App\Integrations\OAuth::getProviders()) |
||
| 362 | ]; |
||
| 363 | break; |
||
| 364 | case 'redirect_uri_id': |
||
| 365 | $params = [ |
||
| 366 | 'name' => $name, |
||
| 367 | 'label' => 'FL_REDIRECT_URI_ID', |
||
| 368 | 'uitype' => 16, |
||
| 369 | 'typeofdata' => 'I~M', |
||
| 370 | 'maximumlength' => '2147483647', |
||
| 371 | 'purifyType' => \App\Purifier::INTEGER, |
||
| 372 | 'blockLabel' => 'BL_BASE', |
||
| 373 | 'tooltip' => 'LBL_REDIRECT_URI_ID_DESC', |
||
| 374 | 'defaultvalue' => '', |
||
| 375 | 'table' => $this->getBaseTable(), |
||
| 376 | 'picklistValues' => array_map(fn ($service) => $service['name'], \App\Integrations\Services::getByType(\App\Integrations\Services::OAUTH)) |
||
| 377 | ]; |
||
| 378 | break; |
||
| 379 | case 'client_id': |
||
| 380 | $params = [ |
||
| 381 | 'name' => $name, |
||
| 382 | 'label' => 'FL_CLIENT_ID', |
||
| 383 | 'uitype' => 1, |
||
| 384 | 'typeofdata' => 'V~M', |
||
| 385 | 'maximumlength' => '255', |
||
| 386 | 'purifyType' => \App\Purifier::TEXT, |
||
| 387 | 'blockLabel' => 'BL_BASE', |
||
| 388 | 'table' => $this->getBaseTable() |
||
| 389 | ]; |
||
| 390 | break; |
||
| 391 | case 'client_secret': |
||
| 392 | $params = [ |
||
| 393 | 'name' => $name, |
||
| 394 | 'label' => 'FL_CLIENT_SECRET', |
||
| 395 | 'uitype' => 99, |
||
| 396 | 'typeofdata' => 'V~M', |
||
| 397 | 'maximumlength' => '255', |
||
| 398 | 'purifyType' => 'raw', |
||
| 399 | 'blockLabel' => 'BL_BASE', |
||
| 400 | 'fromOutsideList' => true, |
||
| 401 | 'table' => $this->getBaseTable() |
||
| 402 | ]; |
||
| 403 | break; |
||
| 404 | default: |
||
| 405 | break; |
||
| 406 | } |
||
| 407 | |||
| 408 | return $params ? \Vtiger_Field_Model::init($this->getName(true), $params, $name) : null; |
||
| 409 | } |
||
| 411 |