YandexDisk::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 10
c 1
b 0
f 0
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);
0 ignored issues
show
Bug introduced by
$this->pathname of type string is incompatible with the type boolean expected by parameter $permanently of Arhitector\Yandex\Disk\Resource\Closed::delete(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
            $item->delete(/** @scrutinizer ignore-type */ $this->pathname);
Loading history...
55 1
        } catch (InvalidArgumentException $e) {
56 1
            throw new Exception($e->getMessage());
57
        }
58
    }
59
}
60