Completed
Pull Request — master (#140)
by Vitaly
04:25
created

AmazonS3v3   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 46
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 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 2
    public function __construct(S3Client $client, string $bucket, array $object)
27
    {
28 2
        $this->client = $client;
29 2
        $this->bucket = $bucket;
30 2
        $this->filename = basename($object['Key']);
31 2
        $this->pathname = $object['Key'];
32 2
        $this->size = $object['Size'];
33 2
        $this->lastModified = strtotime($object['LastModified']);
34 2
    }
35
36
    /**
37
     * Deletes the file.
38
     *
39
     * @throws \phpbu\App\Exception
40
     */
41 1
    public function unlink()
42
    {
43
        try {
44 1
            $this->client->deleteObject([
45 1
                'Bucket' => $this->bucket,
46 1
                'Key' => $this->pathname,
47
            ]);
48
        } catch (\Exception $exception) {
49
            throw new Exception($exception->getMessage());
50
        }
51
    }
52
}