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

AmazonS3v3   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 56
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A isWritable() 0 4 1
A unlink() 0 11 2
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
}