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

GoogleDrive   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 19.15 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 9
loc 47
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A unlink() 0 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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