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

OpenStack::isWritable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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