Completed
Push — master ( 953aec...166410 )
by Sebastian
13s
created

YandexDisk   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 7
loc 35
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A collectBackups() 7 11 4

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
3
namespace phpbu\App\Backup\Collector;
4
5
use Arhitector\Yandex\Disk;
6
use phpbu\App\Backup\Collector;
7
use phpbu\App\Backup\File;
8
use phpbu\App\Backup\Path;
9
use phpbu\App\Backup\Target;
10
11
/**
12
 * YandexDisk class.
13
 *
14
 * @package    phpbu
15
 * @subpackage Backup
16
 * @author     Sebastian Feldmann <[email protected]>
17
 * @author     Alexander Palchikov AxelPAL <[email protected]>
18
 * @copyright  Sebastian Feldmann <[email protected]>
19
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
20
 * @link       http://phpbu.de/
21
 */
22
class YandexDisk extends Remote implements Collector
23
{
24
    /**
25
     * @var Disk
26
     */
27
    protected $disk;
28
29
    /**
30
     * OpenStack constructor.
31
     *
32
     * @param Target $target
33
     * @param Path $path
34
     * @param Disk $disk
35
     */
36 2
    public function __construct(Target $target, Path $path, Disk $disk)
37
    {
38 2
        $this->setUp($target, $path);
39 2
        $this->disk = $disk;
40 2
    }
41
42
    /**
43
     * Collect all created backups.
44
     */
45 2
    protected function collectBackups()
46
    {
47 2
        $items = $this->disk->getResource($this->path->getPathThatIsNotChanging());
48 2 View Code Duplication
        foreach ($items->toArray()['items'] as $item) {
49 2
            if (($item instanceof Disk\Resource\Closed) && $this->isFileMatch($item->getPath())) {
50 2
                $file = new File\YandexDisk($this->disk, $item);
51 2
                $index = $this->getFileIndex($file);
52 2
                $this->files[$index] = $file;
53
            }
54
        }
55 2
    }
56
}
57