Completed
Push — master ( 567a90...f50758 )
by Sebastian
02:46
created

GoogleDrive::unlink()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 3
nop 0
crap 6
1
<?php
2
namespace phpbu\App\Backup\File;
3
4
use Google_Client;
5
use Google_Service_Drive;
6
use Google_Service_Drive_DriveFile;
7
use phpbu\App\Exception;
8
9
/**
10
 * GoogleDrive file class.
11
 *
12
 * @package    phpbu
13
 * @subpackage Backup
14
 * @author     Sebastian Feldmann <[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 GoogleDrive extends Remote
21
{
22
    /**
23
     * Google api client.
24
     *
25
     * @var \Google_Client
26
     */
27
    private $client;
28
29
    /**
30
     * Goole api file id.
31
     *
32
     * @var string
33
     */
34
    private $fileId;
35
36
    /**
37
     * Constructor.
38
     *
39
     * @param \Google_Client                  $client
40
     * @param \Google_Service_Drive_DriveFile $googleFile
41
     */
42 View Code Duplication
    public function __construct(Google_Client $client, Google_Service_Drive_DriveFile $googleFile)
43
    {
44
        $this->client       = $client;
45
        $this->filename     = $googleFile->getName();
1 ignored issue
show
Bug introduced by
Consider using $googleFile->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
46
        $this->pathname     = $googleFile->getId();
47
        $this->fileId       = $googleFile->getId();
48
        $this->size         = $googleFile->getSize();
49
        $this->lastModified = strtotime($googleFile->getCreatedTime());
50
    }
51
52
    /**
53
     * Deletes the file.
54
     *
55
     * @throws \phpbu\App\Exception
56
     */
57
    public function unlink()
58
    {
59
        try {
60
            $service = new Google_Service_Drive($this->client);
61
            $service->files->delete($this->fileId);
62
        } catch (\Exception $e) {
63
            throw new Exception($e->getMessage());
64
        }
65
    }
66
}
67