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

SFTPClient::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
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