| Conditions | 5 |
| Paths | 5 |
| Total Lines | 51 |
| Code Lines | 39 |
| 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 |
||
| 36 | public function getAdapterForSetting(Setting $setting) { |
||
| 37 | switch ($this->key) { |
||
| 38 | case self::TYPE_EMAIL: |
||
| 39 | if (self::$emailAdapter === null) { |
||
| 40 | self::$emailAdapter = new Email([ |
||
| 41 | 'receiver' => new Receiver([ |
||
| 42 | 'imap' => \yii::$app->imap->connection, |
||
| 43 | 'filter' => new Filter(), |
||
| 44 | ]), |
||
| 45 | ]); |
||
| 46 | } |
||
| 47 | |||
| 48 | $adapter = self::$emailAdapter; |
||
| 49 | /** |
||
| 50 | * @var Filter $filter |
||
| 51 | */ |
||
| 52 | $filter = $adapter->receiver->filter; |
||
| 53 | $filter->subject = $setting->email_title_match; |
||
| 54 | $filter->attachmentName = $setting->email_attachment_template; |
||
|
|
|||
| 55 | $filter->sender = $setting->email; |
||
| 56 | break; |
||
| 57 | case self::TYPE_FTP: |
||
| 58 | $adapter = new Ftp([ |
||
| 59 | 'host' => $setting->ftp_host, |
||
| 60 | 'ssl' => $setting->ftp_ssl, |
||
| 61 | 'port' => $setting->ftp_port, |
||
| 62 | 'timeout' => $setting->ftp_timeout, |
||
| 63 | 'login' => $setting->ftp_login, |
||
| 64 | 'password' => $setting->ftp_password, |
||
| 65 | 'dir' => $setting->ftp_dir, |
||
| 66 | 'fileName' => $setting->ftp_file_name, |
||
| 67 | ]); |
||
| 68 | break; |
||
| 69 | case self::TYPE_SITE: |
||
| 70 | $adapter = new Site([ |
||
| 71 | 'site' => $setting->site_host, |
||
| 72 | 'authUrl' => $setting->site_auth_url, |
||
| 73 | 'method' => $setting->site_auth_method, |
||
| 74 | 'loginField' => $setting->site_login_field, |
||
| 75 | 'passwordField' => $setting->site_password_field, |
||
| 76 | 'otherFields' => $setting->siteOtherFields, |
||
| 77 | 'login' => $setting->site_login, |
||
| 78 | 'password' => $setting->site_password, |
||
| 79 | 'fileUrl' => $setting->site_file_url, |
||
| 80 | ]); |
||
| 81 | break; |
||
| 82 | default: |
||
| 83 | throw new Exception('Adapter for source type ' . $this->key . ' is not supported'); |
||
| 84 | } |
||
| 85 | |||
| 86 | return $adapter; |
||
| 87 | } |
||
| 89 |