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

OpenStack   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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