S3::getIdentificationString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Storeman\StorageAdapter;
4
5
use Aws\S3\S3Client;
6
use League\Flysystem\AwsS3v3\AwsS3Adapter;
7
use League\Flysystem\Filesystem;
8
use Storeman\Config\ConfigurationException;
9
use Storeman\Config\VaultConfiguration;
10
11
class S3 extends FlysystemStorageAdapter
12
{
13
    public function __construct(VaultConfiguration $vaultConfiguration)
14
    {
15
        $requiredSettings = [
16
            'bucket',
17
            'key',
18
            'secret',
19
            'region',
20
        ];
21
22 View Code Duplication
        if ($missingSettings = array_diff($requiredSettings, array_keys(array_filter($vaultConfiguration->getSettings()))))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
        {
24
            throw new ConfigurationException("Missing mandatory setting(s): " . implode(',', $missingSettings));
25
        }
26
27
        $client = new S3Client([
28
            'version' => '2006-03-01',
29
            'credentials' => [
30
                'key' => $vaultConfiguration->getSetting('key'),
31
                'secret' => $vaultConfiguration->getSetting('secret'),
32
            ],
33
            'region' => $vaultConfiguration->getSetting('region'),
34
        ]);
35
        $adapter = new AwsS3Adapter($client, $vaultConfiguration->getSetting('bucket'));
36
        $filesystem = new Filesystem($adapter);
37
38
        parent::__construct($filesystem);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public static function getIdentificationString(VaultConfiguration $vaultConfiguration): string
45
    {
46
        return "{$vaultConfiguration->getSetting('username')}@{$vaultConfiguration->getSetting('host')}";
47
    }
48
}
49