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

AmazonS3v3::unlink()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
crap 6
1
<?php
2
namespace phpbu\App\Backup\File;
3
4
use Aws\S3\S3Client;
5
use phpbu\App\Exception;
6
7
class AmazonS3v3 extends Remote
8
{
9
    /**
10
     * @var S3Client
11
     */
12
    protected $client;
13
14
    /**
15
     * @var string
16
     */
17
    protected $bucket;
18
19
    /**
20
     * AmazonS3v3 constructor.
21
     *
22
     * @param S3Client $client
23
     * @param string   $bucket
24
     * @param array    $object
25
     */
26
    public function __construct(S3Client $client, string $bucket, array $object)
27
    {
28
        $this->client = $client;
29
        $this->bucket = $bucket;
30
        $this->filename = basename($object['Key']);
31
        $this->pathname = $object['Key'];
32
        $this->size = $object['Size'];
33
        $this->lastModified = strtotime($object['LastModified']);
34
    }
35
36
    /**
37
     * Return whether the file is writable or not.
38
     *
39
     * @return boolean
40
     */
41
    public function isWritable(): bool
42
    {
43
        return true;
44
    }
45
46
    /**
47
     * Deletes the file.
48
     *
49
     * @throws \phpbu\App\Exception
50
     */
51
    public function unlink()
52
    {
53
        try {
54
            $this->client->deleteObject([
55
                'Bucket' => $this->bucket,
56
                'Key' => $this->pathname,
57
            ]);
58
        } catch (\OpenStack\Common\Error\BadResponseError $exception) {
59
            throw new Exception($exception->getMessage());
60
        }
61
    }
62
}