Completed
Pull Request — master (#140)
by
unknown
04:37
created

AmazonS3v3::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
crap 1
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
}