Completed
Push — master ( 6e7b55...86094f )
by Sebastian
03:17
created

AmazonS3v3::unlink()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
crap 2
1
<?php
2
namespace phpbu\App\Backup\File;
3
4
use Aws\S3\S3Client;
5
use phpbu\App\Exception;
6
7
/**
8
 * AmazonS3v3 class.
9
 *
10
 * @package    phpbu
11
 * @subpackage Backup
12
 * @author     Sebastian Feldmann <[email protected]>
13
 * @author     Vitaly Baev <[email protected]>
14
 * @copyright  Sebastian Feldmann <[email protected]>
15
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
16
 * @link       http://phpbu.de/
17
 * @since      Class available since Release 5.1.0
18
 */
19
class AmazonS3v3 extends Remote
20
{
21
    /**
22
     * @var S3Client
23
     */
24
    protected $client;
25
26
    /**
27
     * @var string
28
     */
29
    protected $bucket;
30
31
    /**
32
     * AmazonS3v3 constructor.
33
     *
34
     * @param S3Client $client
35
     * @param string   $bucket
36
     * @param array    $object
37
     */
38 3
    public function __construct(S3Client $client, string $bucket, array $object)
39
    {
40 3
        $this->client       = $client;
41 3
        $this->bucket       = $bucket;
42 3
        $this->filename     = basename($object['Key']);
43 3
        $this->pathname     = $object['Key'];
44 3
        $this->size         = $object['Size'];
45 3
        $this->lastModified = strtotime($object['LastModified']);
46 3
    }
47
48
    /**
49
     * Deletes the file.
50
     *
51
     * @throws \phpbu\App\Exception
52
     */
53 2
    public function unlink()
54
    {
55
        try {
56 2
            $this->client->deleteObject([
57 2
                'Bucket' => $this->bucket,
58 2
                'Key'    => $this->pathname,
59
            ]);
60 1
        } catch (\Exception $exception) {
61 1
            throw new Exception($exception->getMessage());
62
        }
63 1
    }
64
}
65