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

GoogleDrive   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A unlink() 8 8 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_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