Completed
Push — master ( c34a5d...56c72e )
by WEBEWEB
01:18
created

SFTPClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A connect() 0 9 2
1
<?php
2
3
/**
4
 * This file is part of the ftp-library package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\FTP\Client;
13
14
use WBW\Library\Core\Security\Authenticator;
15
16
/**
17
 * SFTP client.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Library\FTP\Client
21
 */
22
class SFTPClient extends AbstractFTPClient {
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param Authenticator $authenticator The authenticator.
28
     */
29
    public function __construct(Authenticator $authenticator) {
30
        parent::__construct($authenticator);
31
        $this->getAuthenticator()->setScheme("sftp");
0 ignored issues
show
Bug introduced by
The method setScheme() does not seem to exist on object<WBW\Library\Core\Security\Authenticator>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
        if (null === $this->getAuthenticator()->getPort()) {
33
            $this->getAuthenticator()->setPort(22);
34
        }
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function connect($timeout = 90) {
41
        $host = $this->getAuthenticator()->getHost();
42
        $port = $this->getAuthenticator()->getPort();
43
        $this->setConnection(@ftp_ssl_connect($host, $port, $timeout));
44
        if (false === $this->getConnection()) {
45
            throw $this->newFTPException("connection failed");
46
        }
47
        return $this;
48
    }
49
50
}
51