Passed
Push — master ( 5b5e9c...5b3e8e )
by Jay
04:01
created

Ftp::put()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace FMUP;
3
4
use FMUP\Ftp\Factory;
5
6
class Ftp
7
{
8
    const DRIVER = 'driver';
9
    protected $driver;
10
    protected $params = array();
11
    private $driverInstance = null;
12
13
    /**
14
     * @var Factory
15
     */
16
    private $factory;
17
18 9
    public function __construct($params = array())
19
    {
20 9
        $this->driver = isset($params[self::DRIVER]) ? $params[self::DRIVER] : Factory::DRIVER_FTP;
21 9
        $this->params = $params;
22 9
    }
23
24
    /**
25
     * @return Ftp\FtpInterface
26
     * @throws Ftp\Exception
27
     */
28 1
    public function getDriver()
29
    {
30 1
        if (!is_null($this->driverInstance)) {
31 1
            return $this->driverInstance;
32
        }
33
34 1
        $driverInstance = $this->getFactory()->create($this->driver, $this->params);
35 1
        $this->driverInstance = $driverInstance;
36 1
        return $this->driverInstance;
37
    }
38
39
    /**
40
     * @return Factory
41
     */
42 2
    public function getFactory()
43
    {
44 2
        if (!$this->factory) {
45 2
            $this->factory = Factory::getInstance();
46 2
        }
47 2
        return $this->factory;
48
    }
49
50
    /**
51
     * @param Factory $factory
52
     * @return $this
53
     */
54 1
    public function setFactory(Factory $factory)
55
    {
56 1
        $this->factory = $factory;
57 1
        return $this;
58
    }
59
60
    /**
61
     * @param string $host
62
     * @param int $port
63
     * @return $this
64
     */
65 1
    public function connect($host, $port = 21)
66
    {
67 1
        $this->getDriver()->connect($host, $port);
68 1
        return $this;
69
    }
70
71
    /**
72
     * @param string $user
73
     * @param string $pass
74
     * @return bool
75
     */
76 1
    public function login($user, $pass)
77
    {
78 1
        return $this->getDriver()->login($user, $pass);
79
    }
80
81
    /**
82
     * @param string $localFile
83
     * @param string $remoteFile
84
     * @return bool
85
     */
86 1
    public function get($localFile, $remoteFile)
87
    {
88 1
        return $this->getDriver()->get($localFile, $remoteFile);
89
    }
90
91
    /**
92
     * @param string $remoteFile
93
     * @param string $localFile
94
     * @return bool
95
     */
96 1
    public function put($remoteFile, $localFile)
97
    {
98 1
        return $this->getDriver()->put($remoteFile, $localFile);
99
    }
100
101
    /**
102
     * @param $file
103
     * @return bool
104
     */
105 1
    public function delete($file)
106
    {
107 1
        return $this->getDriver()->delete($file);
108
    }
109
110
    /**
111
     * @return bool
112
     */
113 1
    public function close()
114
    {
115 1
        return $this->getDriver()->close();
116
    }
117
}
118