Ftp   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 12
c 1
b 0
f 0
dl 0
loc 48
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A ls() 0 3 1
A isConnected() 0 3 1
A download() 0 3 1
A connect() 0 9 3
A get() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Gateway Client Class
6
 * @category    Ticaje
7
 * @author      Max Demian <[email protected]>
8
 */
9
10
namespace Ticaje\AConnector\Gateway\Client;
11
12
use Ticaje\AConnector\Interfaces\CredentialInterface;
13
use Ticaje\AConnector\Interfaces\Protocol\FtpClientInterface;
14
15
/**
16
 * Class Ftp
17
 * @package Ticaje\AConnector\Gateway\Client
18
 */
19
class Ftp extends Base implements FtpClientInterface
20
{
21
    private $connected;
22
23
    /**
24
     * @inheritDoc
25
     */
26
    public function isConnected(): bool
27
    {
28
        return $this->connected;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function connect(CredentialInterface $credentials)
35
    {
36
        try {
37
            $this->client = $this->clientFactory->create($credentials->getAll());
38
            $this->connected = $this->client->login($credentials->username, $credentials->password) ? true : false;
0 ignored issues
show
Bug introduced by
Accessing password on the interface Ticaje\AConnector\Interfaces\CredentialInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Accessing username on the interface Ticaje\AConnector\Interfaces\CredentialInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
39
        } catch (\Exception $exception) {
40
            $this->connected = false;
41
        }
42
        return $this->connected;
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public function get($path = '')
49
    {
50
        return $this->client->get($path);
51
    }
52
53
    /**
54
     * @inheritDoc
55
     */
56
    public function ls($dir = '.'): array
57
    {
58
        return $this->client->nlist($dir);
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    public function download($path = '', $destination = false)
65
    {
66
        return $this->client->get($path, $destination);
67
    }
68
}
69