HasCloudDriverTrait::formatS3Config()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 4
eloc 8
c 2
b 0
f 1
nc 4
nop 1
dl 0
loc 14
ccs 0
cts 9
cp 0
crap 20
rs 10
1
<?php
2
3
namespace Nip\Filesystem\FilesystemManager;
4
5
use Aws\S3\S3Client;
6
use League\Flysystem\AwsS3v3\AwsS3Adapter as S3Adapter;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\AwsS3v3\AwsS3Adapter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use League\Flysystem\FilesystemInterface;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\FilesystemInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Nip\Filesystem\FileDisk;
9
10
/**
11
 * Trait HasCloudDriverTrait
12
 * @package Nip\Filesystem\FilesystemManager
13
 */
14
trait HasCloudDriverTrait
15
{
16
    /**
17
     * Create an instance of the Amazon S3 driver.
18
     *
19
     * @param array $config
20
     * @return FilesystemInterface|FileDisk
21
     */
22
    public function createS3Driver(array $config)
23
    {
24
        $s3Config = $this->formatS3Config($config);
25
        $root = $s3Config['root'] ?? null;
26
        $options = $config['options'] ?? [];
27
28
        return $this->adapt($this->createDisk(
0 ignored issues
show
Bug introduced by
It seems like adapt() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

28
        return $this->/** @scrutinizer ignore-call */ adapt($this->createDisk(
Loading history...
Bug introduced by
It seems like createDisk() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

28
        return $this->adapt($this->/** @scrutinizer ignore-call */ createDisk(
Loading history...
29
            new S3Adapter(new S3Client($s3Config), $s3Config['bucket'], $root, $options),
30
            $config
31
        ));
32
    }
33
34
    /**
35
     * Format the given S3 configuration with the default options.
36
     *
37
     * @param array $config
38
     * @return array
39
     */
40
    protected function formatS3Config(array $config)
41
    {
42
        $config += ['version' => 'latest'];
43
        if ($config['key'] && $config['secret']) {
44
            $config['credentials'] = [
45
                'key' => $config['key'],
46
                'secret' => $config['secret'],
47
            ];
48
        }
49
        if (empty($config['endpoint'])) {
50
            unset($config['endpoint']);
51
        }
52
53
        return $config;
54
    }
55
}
56