Completed
Push — master ( ccde76...68a462 )
by Sebastian
12s
created

OpenStack::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
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