Completed
Push — master ( 57aec2...cfc6e9 )
by Sebastian
06:16
created

Dropbox::getBackupFiles()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 10
cts 10
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 5
nop 0
crap 5
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
/**
9
 * Dropbox class.
10
 *
11
 * @package    phpbu
12
 * @subpackage Backup
13
 * @author     Sebastian Feldmann <[email protected]>
14
 * @author     Vitaly Baev <[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 Dropbox extends Collector
21
{
22
    /**
23
     * @var DropboxApi
24
     */
25
    protected $client;
26
27
    /**
28
     * OpenStack remote path
29
     *
30
     * @var string
31
     */
32
    protected $path;
33
34
    /**
35
     * OpenStack constructor.
36
     *
37
     * @param \phpbu\App\Backup\Target $target
38
     * @param DropboxApi               $client
39
     * @param string                   $path
40
     */
41 1
    public function __construct(Target $target, DropboxApi $client, string $path)
42
    {
43 1
        $this->client = $client;
44 1
        $this->path   = $path;
45 1
        $this->setUp($target);
46 1
    }
47
48
    /**
49
     * Get all created backups.
50
     *
51
     * @return \phpbu\App\Backup\File[]
52
     */
53 1
    public function getBackupFiles() : array
54
    {
55 1
        $items = $this->client->listFolder($this->path, ['limit' => 100]);
56 1
        foreach ($items->getItems() as $item) {
57
            // skip directories
58 1
            if ($item instanceof \Kunnu\Dropbox\Models\FolderMetadata) {
59 1
                continue;
60
            }
61
            /** @var \Kunnu\Dropbox\Models\FileMetadata $item */
62
            // skip currently created backup
63 1
            if ($item->getPathDisplay() == $this->path . $this->target->getFilename()) {
64 1
                continue;
65
            }
66 1
            if ($this->isFilenameMatch($item->getName())) {
67 1
                $this->files[] = new \phpbu\App\Backup\File\Dropbox($this->client, $item);
68
            }
69
        }
70
71 1
        return $this->files;
72
    }
73
}
74