Completed
Push — master ( 281cc9...fac822 )
by Sebastian
13:32 queued 10:28
created

AzureBlob::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 9
cts 9
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
namespace phpbu\App\Backup\File;
3
4
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
5
use MicrosoftAzure\Storage\Blob\Models\Blob;
6
use phpbu\App\Exception;
7
8
/**
9
 * AzureBlob class.
10
 *
11
 * @package    phpbu
12
 * @subpackage Backup
13
 * @author     Sebastian Feldmann <[email protected]>
14
 * @author     Jonathan Bouzekri <[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.2.7
19
 */
20
class AzureBlob extends Remote
21
{
22
    /**
23
     * Azure Blob client.
24
     *
25
     * @var BlobRestProxy
26
     */
27
    private $client;
28
29
    /**
30
     * @var string
31
     */
32
    protected $containerName;
33
34
    /**
35
     * AzureBlob constructor.
36
     *
37
     * @param BlobRestProxy $client
38
     * @param string        $containerName
39
     * @param Blob          $blob
40
     */
41 3
    public function __construct(BlobRestProxy $client, string $containerName, Blob $blob)
42
    {
43 3
        $this->client        = $client;
44 3
        $this->containerName = $containerName;
45 3
        $this->filename      = basename($blob->getName());
46 3
        $this->pathname      = $blob->getName();
47 3
        $props               = $blob->getProperties();
48 3
        $this->size          = $props->getContentLength();
49 3
        $this->lastModified  = $props->getLastModified()->getTimestamp();
50 3
    }
51
52
    /**
53
     * Deletes the file.
54
     *
55
     * @throws \phpbu\App\Exception
56
     */
57 2
    public function unlink()
58
    {
59
        try {
60 2
            $this->client->deleteBlob($this->containerName, $this->pathname);
61 1
        } catch (\Exception $exception) {
62 1
            throw new Exception($exception->getMessage());
63
        }
64 1
    }
65
}
66