Completed
Pull Request — master (#140)
by
unknown
03:55
created

OpenStack   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 45
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A isWritable() 0 4 1
A unlink() 0 8 2
1
<?php
2
3
namespace phpbu\App\Backup\File;
4
5
use OpenStack\ObjectStore\v1\Models\Container;
6
use OpenStack\ObjectStore\v1\Models\StorageObject;
7
use phpbu\App\Exception;
8
9
class OpenStack extends Remote
10
{
11
    /**
12
     * @var Container
13
     */
14
    protected $container;
15
16
    /**
17
     * OpenStack constructor.
18
     *
19
     * @param Container $container
20
     */
21
    public function __construct(Container $container, StorageObject $object)
22
    {
23
        $this->container = $container;
24
        $this->filename = basename($object->name);
25
        $this->pathname = $object->name;
26
        $this->size = (int)$object->contentLength;
27
        $this->lastModified = $object->lastModified->getTimestamp();
0 ignored issues
show
Bug introduced by
The method getTimestamp cannot be called on $object->lastModified (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
28
    }
29
30
    /**
31
     * Return whether the file is writable or not.
32
     *
33
     * @return boolean
34
     */
35
    public function isWritable(): bool
36
    {
37
        return true;
38
    }
39
40
    /**
41
     * Deletes the file.
42
     *
43
     * @throws \phpbu\App\Exception
44
     */
45
    public function unlink()
46
    {
47
        try {
48
            $this->container->getObject($this->getPathname())->delete();
49
        } catch (\OpenStack\Common\Error\BadResponseError $exception) {
50
            throw new Exception($exception->getMessage());
51
        }
52
    }
53
}