Completed
Push — master ( 953aec...166410 )
by Sebastian
13s
created

YandexDisk::unlink()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 6
cp 0.8333
rs 9.9666
c 0
b 0
f 0
cc 2
nc 3
nop 0
crap 2.0185
1
<?php
2
3
namespace phpbu\App\Backup\File;
4
5
use Arhitector\Yandex\Disk;
6
use Arhitector\Yandex\Disk\Resource\Closed;
7
use InvalidArgumentException;
8
use phpbu\App\Exception;
9
10
/**
11
 * YandexDisk class.
12
 *
13
 * @package    phpbu
14
 * @subpackage Backup
15
 * @author     Sebastian Feldmann <[email protected]>
16
 * @author     Alexander Palchikov AxelPAL <[email protected]>
17
 * @copyright  Sebastian Feldmann <[email protected]>
18
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
19
 * @link       http://phpbu.de/
20
 */
21
class YandexDisk extends Remote
22
{
23
    /**
24
     * YandexDisk api client.
25
     *
26
     * @var Disk
27
     */
28
    protected $disk;
29
30
    /**
31
     * YandexDisk constructor.
32
     *
33
     * @param Disk $disk
34
     * @param Closed $yandexFile
35
     */
36 4
    public function __construct(Disk $disk, Closed $yandexFile)
37
    {
38 4
        $this->disk = $disk;
39 4
        $this->filename = $yandexFile->get('name');
40 4
        $this->pathname = $yandexFile->get('path');
41 4
        $this->size = $yandexFile->get('size');
42 4
        $this->lastModified = strtotime($yandexFile->get('modified'));
43 4
    }
44
45
    /**
46
     * Deletes the file on YandexDisk.
47
     *
48
     * @throws Exception
49
     */
50 1
    public function unlink()
51
    {
52
        try {
53 1
            $item = $this->disk->getResource($this->pathname);
54 1
            $item->delete($this->pathname);
55 1
        } catch (InvalidArgumentException $e) {
56 1
            throw new Exception($e->getMessage());
57
        }
58
    }
59
}
60