Ftp::getClient()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
ccs 3
cts 5
cp 0.6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.2559
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
}