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

Ftp   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A unlink() 0 9 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