Completed
Pull Request — master (#140)
by
unknown
04:37
created

OpenStack   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 36
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A unlink() 0 8 2
1
<?php
2
namespace phpbu\App\Backup\File;
3
4
use OpenStack\ObjectStore\v1\Models\Container;
5
use OpenStack\ObjectStore\v1\Models\StorageObject;
6
use phpbu\App\Exception;
7
8
class OpenStack extends Remote
9
{
10
    /**
11
     * @var Container
12
     */
13
    protected $container;
14
15
    /**
16
     * OpenStack constructor.
17
     *
18
     * @param Container     $container
19
     * @param StorageObject $object
20
     */
21 2
    public function __construct($container, $object)
22
    {
23 2
        $this->container = $container;
24 2
        $this->filename = basename($object->name);
25 2
        $this->pathname = $object->name;
26 2
        $this->size = (int)$object->contentLength;
27 2
        $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 2
    }
29
30
    /**
31
     * Deletes the file.
32
     *
33
     * @throws \phpbu\App\Exception
34
     */
35 1
    public function unlink()
36
    {
37
        try {
38 1
            $this->container->getObject($this->getPathname())->delete();
39
        } catch (\OpenStack\Common\Error\BadResponseError $exception) {
40
            throw new Exception($exception->getMessage());
41
        }
42
    }
43
}