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

Dropbox::unlink()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php
2
namespace phpbu\App\Backup\File;
3
4
use Kunnu\Dropbox\Dropbox as DropboxApi;
5
use Kunnu\Dropbox\Models\FileMetadata;
6
7
/**
8
 * Dropbox class.
9
 *
10
 * @package    phpbu
11
 * @subpackage Backup
12
 * @author     Sebastian Feldmann <[email protected]>
13
 * @author     Vitaly Baev <[email protected]>
14
 * @copyright  Sebastian Feldmann <[email protected]>
15
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
16
 * @link       http://phpbu.de/
17
 * @since      Class available since Release 5.1.0
18
 */
19
class Dropbox extends Remote
20
{
21
    /**
22
     * @var DropboxApi
23
     */
24
    protected $client;
25
26
    /**
27
     * Dropbox constructor.
28
     *
29
     * @param DropboxApi   $client
30
     * @param FileMetadata $dropboxFile
31
     */
32 3
    public function __construct(DropboxApi $client, FileMetadata $dropboxFile)
33
    {
34 3
        $this->client       = $client;
35 3
        $this->filename     = $dropboxFile->getName();
36 3
        $this->pathname     = $dropboxFile->getPathDisplay();
37 3
        $this->size         = $dropboxFile->getSize();
38 3
        $this->lastModified = strtotime($dropboxFile->getClientModified());
39 3
    }
40
41
    /**
42
     * Deletes the file.
43
     *
44
     * @throws \phpbu\App\Exception
45
     */
46 2
    public function unlink()
47
    {
48
        try {
49 2
            $this->client->delete($this->pathname);
50 1
        } catch (\Exception $e) {
51 1
            throw new \phpbu\App\Exception($e->getMessage());
52
        }
53 1
    }
54
}
55