Completed
Pull Request — master (#146)
by Vitaly
09:53
created

OpenStack::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
crap 1
1
<?php
2
namespace phpbu\App\Backup\Collector;
3
4
use OpenStack\ObjectStore\v1\Models\Container;
5
use OpenStack\ObjectStore\v1\Models\StorageObject;
6
use phpbu\App\Backup\Collector;
7
use phpbu\App\Backup\Path;
8
use phpbu\App\Backup\Target;
9
use phpbu\App\Util;
10
11
/**
12
 * OpenStack collector class.
13
 *
14
 * @package    phpbu
15
 * @subpackage Backup
16
 * @author     Sebastian Feldmann <[email protected]>
17
 * @author     Vitaly Baev <[email protected]>
18
 * @copyright  Sebastian Feldmann <[email protected]>
19
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
20
 * @link       http://phpbu.de/
21
 * @since      Class available since Release 5.1.0
22
 */
23
class OpenStack extends Remote implements Collector
24
{
25
    /**
26
     * @var \OpenStack\ObjectStore\v1\Models\Container
27
     */
28
    protected $container;
29
30
    /**
31
     * OpenStack constructor.
32
     *
33
     * @param \phpbu\App\Backup\Target                   $target
34
     * @param \phpbu\App\Backup\Path                     $path
35
     * @param \OpenStack\ObjectStore\v1\Models\Container $container
36
     */
37 1
    public function __construct(Target $target, Path $path, Container $container)
38
    {
39 1
        $this->setUp($target, $path);
40 1
        $this->container = $container;
41 1
    }
42
43
    /**
44
     * Collect all created backups.
45
     */
46 1
    protected function collectBackups()
47
    {
48
        // get all objects matching our path prefix
49 1
        $remotePath = Util\Path::withTrailingSlash($this->path->getPathThatIsNotChanging());
50 1
        $remotePath = $remotePath == '/' ? '' : $remotePath;
51
52 1
        $objects    = $this->container->listObjects(['prefix' => $remotePath]);
53
        /** @var StorageObject $object */
54 1
        foreach ($objects as $object) {
55 1
            // skip directories
56
            if ($object->contentType == 'application/directory') {
57 1
                continue;
58 1
            }
59 1
            if ($this->isFileMatch($object->name)) {
60 1
                $file                = new \phpbu\App\Backup\File\OpenStack($this->container, $object);
61
                $index               = $this->getFileIndex($file);
62
                $this->files[$index] = $file;
63
            }
64 1
        }
65
66
        return $this->files;
67
    }
68
}
69