AmazonS3v2   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 34
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A sync() 0 24 2
1
<?php
2
namespace phpbu\App\Backup\Sync;
3
4
use Aws\S3\S3Client;
5
use phpbu\App\Result;
6
use phpbu\App\Backup\Target;
7
8
/**
9
 * Amazon S3 Sync
10
 *
11
 * @package    phpbu
12
 * @subpackage Backup
13
 * @author     Sebastian Feldmann <[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 1.1.4
18
 */
19
class AmazonS3v2 extends AmazonS3
20
{
21
    /**
22
     * Execute the sync.
23
     *
24
     * @see    \phpbu\App\Backup\Sync::sync()
25
     * @param  \phpbu\App\Backup\Target $target
26
     * @param  \phpbu\App\Result        $result
27
     * @throws \phpbu\App\Backup\Sync\Exception
28
     */
29
    public function sync(Target $target, Result $result)
30
    {
31
        $sourcePath = $target->getPathname();
32
        $targetPath = $this->path . '/' .  $target->getFilename();
33
34
        $s3 = S3Client::factory(
0 ignored issues
show
Deprecated Code introduced by
The function Aws\AwsClient::factory() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

34
        $s3 = /** @scrutinizer ignore-deprecated */ S3Client::factory(
Loading history...
35
            [
36
                'signature' => 'v4',
37
                'region'    => $this->region,
38
                'credentials' => [
39
                    'key'    => $this->key,
40
                    'secret' => $this->secret,
41
                ]
42
            ]
43
        );
44
45
        try {
46
            $fh = fopen($sourcePath, 'r');
47
            $s3->upload($this->bucket, $targetPath, $fh, $this->acl);
48
        } catch (\Exception $e) {
49
            throw new Exception($e->getMessage(), null, $e);
50
        }
51
52
        $result->debug('upload: done');
53
    }
54
}
55