Completed
Pull Request — master (#140)
by
unknown
05:29
created

OpenStack::getBackupFiles()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 8.7624
c 0
b 0
f 0
cc 5
eloc 10
nc 5
nop 0
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