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