Passed
Push — master ( 30e7f6...e34ab3 )
by Hector Luis
12:09
created

Ftp::isConnected()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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