Completed
Pull Request — master (#140)
by Vitaly
04:25
created

Dropbox::getBackupFiles()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5.025

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 9
cts 10
cp 0.9
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 5
nop 0
crap 5.025
1
<?php
2
namespace phpbu\App\Backup\Collector;
3
4
use Kunnu\Dropbox\Dropbox as DropboxApi;
5
use phpbu\App\Backup\Collector;
6
use phpbu\App\Backup\Target;
7
8
class Dropbox extends Collector
9
{
10
    /**
11
     * @var DropboxApi
12
     */
13
    protected $client;
14
15
    /**
16
     * OpenStack remote path
17
     *
18
     * @var string
19
     */
20
    protected $path;
21
22
    /**
23
     * OpenStack constructor.
24
     *
25
     * @param \phpbu\App\Backup\Target $target
26
     * @param DropboxApi               $client
27
     * @param string                   $path
28
     */
29 1
    public function __construct(Target $target, DropboxApi $client, string $path)
30
    {
31 1
        $this->client = $client;
32 1
        $this->path = $path;
33 1
        $this->setUp($target);
34 1
    }
35
36
    /**
37
     * Get all created backups.
38
     *
39
     * @return \phpbu\App\Backup\File[]
40
     */
41 1
    public function getBackupFiles(): array
42
    {
43 1
        $items = $this->client->listFolder($this->path, ['limit' => 100]);
44 1
        foreach ($items->getItems() as $item) {
45
            // skip directories
46 1
            if ($item instanceof \Kunnu\Dropbox\Models\FolderMetadata) {
47
                continue;
48
            }
49
            /** @var \Kunnu\Dropbox\Models\FileMetadata $item */
50
            // skip currently created backup
51 1
            if ($item->getPathDisplay() == $this->path . $this->target->getFilename()) {
52 1
                continue;
53
            }
54 1
            if ($this->isFilenameMatch($item->getName())) {
55 1
                $this->files[] = new \phpbu\App\Backup\File\Dropbox($this->client, $item);
56
            }
57
        }
58
59 1
        return $this->files;
60
    }
61
}