Completed
Push — master ( 98eb2f...d0859a )
by Sebastian
32s queued 24s
created

BackblazeS3   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 10
c 2
b 1
f 0
dl 0
loc 30
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createClient() 0 11 1
A createEndpoint() 0 3 1
1
<?php
2
3
namespace phpbu\App\Backup\Sync;
4
5
use Aws\S3\S3Client;
6
7
/**
8
 * Backblaze Sync
9
 *
10
 * Docs example
11
 * https://help.backblaze.com/hc/en-us/articles/360046980814-Using-the-AWS-SDK-for-PHP-with-Backblaze-B2-Cloud-Storage
12
 *
13
 * @package    phpbu
14
 * @subpackage Backup
15
 * @author     Vladimir Konchakovsky <[email protected]>
16
 * @copyright  Vladimir Konchakovsky <[email protected]>
17
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
18
 * @link       http://phpbu.de/
19
 */
20
class BackblazeS3 extends AmazonS3v3
21
{
22
    /**
23
     * Create the Backblaze AWS client.
24
     *
25
     * @return \Aws\S3\S3Client
26
     */
27
    protected function createClient() : S3Client
28
    {
29
        $endpoint = $this->createEndpoint();
30
31
        return new S3Client([
32
            'endpoint'    => $endpoint,
33
            'region'      => $this->region,
34
            'version'     => 'latest',
35
            'credentials' => [
36
                'key'    => $this->key,
37
                'secret' => $this->secret,
38
            ]
39
        ]);
40
    }
41
42
    /**
43
     * Generate Backblaze enpoint
44
     *
45
     * @return string
46
     */
47
    private function createEndpoint()
48
    {
49
        return strtr('https://s3.{region}.backblazeb2.com', '{region}', $this->region);
50
    }
51
}
52