Completed
Push — master ( 700a98...214a89 )
by Sebastian
05:41
created

GoogleDrive::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 8
cts 8
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 2
crap 1
1
<?php
2
namespace phpbu\App\Backup\File;
3
4
use Google_Service_Drive;
5
use Google_Service_Drive_DriveFile;
6
use phpbu\App\Exception;
7
8
/**
9
 * Google Drive file class.
10
 *
11
 * @package    phpbu
12
 * @subpackage Backup
13
 * @author     Sebastian Feldmann <[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 View Code Duplication
class GoogleDrive extends Remote
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
{
21
    /**
22
     * Google drive api service.
23
     *
24
     * @var \Google_Service_Drive
25
     */
26
    private $service;
27
28
    /**
29
     * Goole api file id.
30
     *
31
     * @var string
32
     */
33
    private $fileId;
34
35
    /**
36
     * Constructor.
37
     *
38
     * @param \Google_Service_Drive           $service
39
     * @param \Google_Service_Drive_DriveFile $googleFile
40
     */
41 3
    public function __construct(Google_Service_Drive $service, Google_Service_Drive_DriveFile $googleFile)
42
    {
43 3
        $this->service      = $service;
44 3
        $this->filename     = $googleFile->getName();
45 3
        $this->pathname     = $googleFile->getId();
46 3
        $this->fileId       = $googleFile->getId();
47 3
        $this->size         = $googleFile->getSize();
48 3
        $this->lastModified = strtotime($googleFile->getCreatedTime());
49 3
    }
50
51
    /**
52
     * Deletes the file.
53
     *
54
     * @throws \phpbu\App\Exception
55
     */
56 2
    public function unlink()
57
    {
58
        try {
59 2
            $this->service->files->delete($this->fileId);
60 1
        } catch (\Exception $e) {
61 1
            throw new Exception($e->getMessage());
62
        }
63 1
    }
64
}
65