Completed
Pull Request — master (#140)
by
unknown
03:55
created

OpenStack   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 55
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B getBackupFiles() 0 21 5
1
<?php
2
namespace phpbu\App\Backup\Collector;
3
4
use OpenStack\ObjectStore\v1\Models\Container;
5
use phpbu\App\Backup\Collector;
6
use phpbu\App\Backup\Sync\Openstack as OpenStackSync;
7
use OpenStack\ObjectStore\v1\Models\StorageObject;
8
use phpbu\App\Backup\Target;
9
10
class OpenStack extends Collector
11
{
12
    /**
13
     * @var Container
14
     */
15
    protected $container;
16
17
    /**
18
     * Path where to search for backup files
19
     *
20
     * @var string
21
     */
22
    protected $path;
23
24
    /**
25
     * OpenStack constructor.
26
     *
27
     * @param \phpbu\App\Backup\Target $target
28
     * @param Container                $container
29
     * @param string                   $path
30
     */
31
    public function __construct(Target $target, Container $container, string $path)
32
    {
33
        $this->container = $container;
34
        $this->path = $path;
35
        $this->setUp($target);
36
    }
37
38
    /**
39
     * Get all created backups.
40
     *
41
     * @return \phpbu\App\Backup\File[]
42
     */
43
    public function getBackupFiles(): array
44
    {
45
        // get all objects matching our path prefix
46
        $objects = $this->container->listObjects(['prefix' => $this->path]);
47
        /** @var StorageObject $object */
48
        foreach ($objects as $object) {
49
            // skip directories
50
            if ($object->contentType == 'application/directory') {
51
                continue;
52
            }
53
            // skip currently created backup
54
            if ($object->name == $this->path . $this->target->getFilename()) {
55
                continue;
56
            }
57
            if ($this->isFilenameMatch(basename($object->name))) {
58
                $this->files[] = new \phpbu\App\Backup\File\OpenStack($this->container, $object);
59
            }
60
        }
61
62
        return $this->files;
63
    }
64
}
65