Completed
Push — master ( 6aac25...fc5b3c )
by Sebastian
04:08 queued 01:04
created

OpenStack::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 1
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
/**
9
 * OpenStack class.
10
 *
11
 * @package    phpbu
12
 * @subpackage Backup
13
 * @author     Sebastian Feldmann <[email protected]>
14
 * @author     Vitaly Baev <[email protected]>
15
 * @copyright  Sebastian Feldmann <[email protected]>
16
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
17
 * @link       http://phpbu.de/
18
 * @since      Class available since Release 5.1.0
19
 */
20
class OpenStack extends Remote
21
{
22
    /**
23
     * @var Container
24
     */
25
    protected $container;
26
27
    /**
28
     * OpenStack constructor.
29
     *
30
     * @param Container     $container
31
     * @param StorageObject $object
32
     */
33 2
    public function __construct($container, $object)
34
    {
35 2
        $this->container    = $container;
36 2
        $this->filename     = basename($object->name);
37 2
        $this->pathname     = $object->name;
38 2
        $this->size         = (int)$object->contentLength;
39 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...
40 2
    }
41
42
    /**
43
     * Deletes the file.
44
     *
45
     * @throws \phpbu\App\Exception
46
     */
47 1
    public function unlink()
48
    {
49
        try {
50 1
            $this->container->getObject($this->getPathname())->delete();
51
        } catch (\Exception $exception) {
52
            throw new Exception($exception->getMessage());
53
        }
54 1
    }
55
}
56