Passed
Push — master ( 8294c3...31b270 )
by eXeCUT
03:49
created

FilesSource   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 43
c 1
b 0
f 0
dl 0
loc 59
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAdapterForSetting() 0 48 4
1
<?php
2
3
namespace execut\import\models;
4
5
use execut\import\components\source\adapter\Email;
6
use execut\import\components\source\adapter\email\Filter;
7
use execut\import\components\source\adapter\email\Receiver;
8
use execut\import\components\source\adapter\email\ReceiverCache;
9
use execut\import\components\source\adapter\Ftp;
10
use execut\import\components\source\adapter\Site;
11
use execut\yii\base\Exception;
12
use Yii;
13
use yii\helpers\ArrayHelper;
14
15
/**
16
 * This is the model class for table "import_files_sources".
17
 *
18
 * @property integer $id
19
 * @property string $created
20
 * @property string $updated
21
 * @property string $name
22
 * @property string $key
23
 *
24
 * @property \execut\import\models\File[] $importFiles
25
 */
26
class FilesSource extends base\FilesSource
27
{
28
    protected static $emailAdapter = null;
29
//    const ALL_TYPES = [
30
//        self::TYPE_EMAIL,
31
//        self::TYPE_FTP,
32
//        self::TYPE_SITE,
33
//    ];
34
    const TYPE_EMAIL = 'email';
35
    const TYPE_FTP = 'ftp';
36
    const TYPE_SITE = 'site';
37
    public function getAdapterForSetting(Setting $setting) {
38
        switch ($this->key) {
39
            case self::TYPE_EMAIL:
40
                $adapter = new Email([
41
                    'receiver' => new Receiver([
42
                        'imap' => \yii::$app->imap->connection,
43
                        'filter' => new Filter(),
44
                        'cache' => new ReceiverCache()
45
                    ]),
46
                ]);
47
                /**
48
                 * @var Filter $filter
49
                 */
50
                $filter = $adapter->receiver->filter;
51
                $filter->subject = $setting->email_title_match;
52
                $filter->attachmentName = $setting->email_attachment_template;
0 ignored issues
show
Bug Best Practice introduced by
The property email_attachment_template does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
53
                $filter->sender = $setting->email;
54
            break;
55
            case self::TYPE_FTP:
56
                $adapter = new Ftp([
57
                    'host' => $setting->ftp_host,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_host does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
58
                    'ssl' => $setting->ftp_ssl,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_ssl does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
59
                    'port' => $setting->ftp_port,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_port does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
60
                    'timeout' => $setting->ftp_timeout,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_timeout does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
61
                    'login' => $setting->ftp_login,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_login does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
62
                    'password' => $setting->ftp_password,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_password does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
63
                    'dir' => $setting->ftp_dir,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_dir does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
64
                    'fileName' => $setting->ftp_file_name,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_file_name does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
65
                ]);
66
            break;
67
            case self::TYPE_SITE:
68
                $adapter = new Site([
69
                    'site' => $setting->site_host,
0 ignored issues
show
Bug Best Practice introduced by
The property site_host does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
70
                    'authUrl' => $setting->site_auth_url,
0 ignored issues
show
Bug Best Practice introduced by
The property site_auth_url does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
71
                    'method' => $setting->site_auth_method,
0 ignored issues
show
Bug Best Practice introduced by
The property site_auth_method does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
72
                    'loginField' => $setting->site_login_field,
0 ignored issues
show
Bug Best Practice introduced by
The property site_login_field does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
73
                    'passwordField' => $setting->site_password_field,
0 ignored issues
show
Bug Best Practice introduced by
The property site_password_field does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
74
                    'otherFields' => $setting->siteOtherFields,
0 ignored issues
show
Bug Best Practice introduced by
The property siteOtherFields does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
75
                    'login' => $setting->site_login,
0 ignored issues
show
Bug Best Practice introduced by
The property site_login does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
76
                    'password' => $setting->site_password,
0 ignored issues
show
Bug Best Practice introduced by
The property site_password does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
77
                    'fileUrl' => $setting->site_file_url,
0 ignored issues
show
Bug Best Practice introduced by
The property site_file_url does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
78
                ]);
79
            break;
80
            default:
81
                throw new Exception('Adapter for source type ' . $this->key . ' is not supported');
82
        }
83
84
        return $adapter;
85
    }
86
}
87