Completed
Push — master ( 6e7b55...86094f )
by Sebastian
03:17
created

Ftp::unlink()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 3
nop 0
crap 2
1
<?php
2
namespace phpbu\App\Backup\File;
3
4
use phpbu\App\Exception;
5
use SebastianFeldmann\Ftp\Client;
6
use SebastianFeldmann\Ftp\File;
7
8
/**
9
 * Ftp file class.
10
 *
11
 * @package    phpbu
12
 * @subpackage Backup
13
 * @author     Sebastian Feldmann <[email protected]>
14
 * @author     Vitaly Baev <[email protected]>
15
 * @copyright  Sebastian Feldmann <[email protected]>
16
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
17
 * @link       http://phpbu.de/
18
 * @since      Class available since Release 5.1.0
19
 */
20
class Ftp extends Remote
21
{
22
    /**
23
     * FTP client class, handling FTP connection and commands.
24
     *
25
     * @var \SebastianFeldmann\Ftp\Client
26
     */
27
    private $ftpClient;
28
29
    /**
30
     * Ftp constructor.
31
     *
32
     * @param \SebastianFeldmann\Ftp\Client $ftpClient
33
     * @param \SebastianFeldmann\Ftp\File   $ftpFile
34
     * @param string                        $path
35
     */
36 5
    public function __construct(Client $ftpClient, File $ftpFile, string $path)
37
    {
38 5
        $this->ftpClient    = $ftpClient;
39 5
        $this->filename     = $ftpFile->getFilename();
40 5
        $this->pathname     = (!empty($path) ? rtrim($path, '/') . '/' : '') . $ftpFile->getFilename();
41 5
        $this->size         = $ftpFile->getSize();
42 5
        $this->lastModified = $ftpFile->getLastModifyDate()->getTimestamp();
43 5
    }
44
45
    /**
46
     * Deletes the file.
47
     *
48
     * @throws \phpbu\App\Exception
49
     */
50 2
    public function unlink()
51
    {
52
        try {
53 2
            $this->ftpClient->chHome();
54 2
            $this->ftpClient->delete($this->pathname);
55 1
        } catch (\Exception $e) {
56 1
            throw new Exception($e->getMessage());
57
        }
58 1
    }
59
}
60