Ftp   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 4
eloc 25
dl 0
loc 39
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setClient() 0 3 1
A getClient() 0 8 2
A getFiles() 0 12 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: execut
5
 * Date: 9/28/16
6
 * Time: 4:45 PM
7
 */
8
9
namespace execut\import\components\source\adapter;
10
11
12
use execut\import\components\source\Adapter;
13
use execut\import\components\source\File;
14
use yii\base\Component;
15
use yii2mod\ftp\FtpClient;
16
17
class Ftp extends Adapter
18
{
19
    public $host = null;
20
    public $ssl = false;
21
    public $port = 21;
22
    public $timeout = 90;
23
    public $login = null;
24
    public $password = null;
25
    public $dir = null;
26
    public $fileName = null;
27
    protected $client = null;
28 1
    public function getFiles() {
29 1
        $client = $this->getClient();
30 1
        $file = $this->createFile($this->fileName);
31
32 1
        $client->connect($this->host, $this->ssl, $this->port, $this->timeout);
33 1
        $client->login($this->login, $this->password);
34 1
        $client->raw('OPTS UTF8 ON');
35 1
        $client->pasv(true);
36 1
        $client->get($file->filePath, trim($this->dir, '/') . '/' . $this->fileName, FTP_BINARY);
37
38
        return [
39 1
            $file,
40
        ];
41
    }
42
43 1
    public function setClient($client) {
44 1
        $this->client = $client;
45 1
        return $this;
46
    }
47
48 1
    public function getClient() {
49 1
        if ($this->client !== null) {
50 1
            return $this->client;
51
        }
52
53
        $client = new FtpClient();
54
55
        return $this->client = $client;
56
    }
57
}