Passed
Pull Request — master (#407)
by Kirill
06:59
created

AwsS3FsBuilderTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A buildAwsS3Info() 0 3 1
A getAwsS3VisibilityOption() 0 6 1
A getAwsS3Client() 0 6 1
A buildAwsS3ServerDescription() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Tests\Storage\Traits;
6
7
use Aws\Credentials\Credentials;
8
use Aws\S3\S3Client;
9
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
10
use League\Flysystem\AwsS3V3\PortableVisibilityConverter;
11
use League\Flysystem\Visibility;
12
use Spiral\Storage\Config\DTO\FileSystemInfo\Aws\AwsS3Info;
13
use Spiral\Storage\Exception\StorageException;
14
15
trait AwsS3FsBuilderTrait
16
{
17
    /**
18
     * @param string|null $name
19
     *
20
     * @return AwsS3Info
21
     *
22
     * @throws StorageException
23
     */
24
    protected function buildAwsS3Info(?string $name = self::SERVER_NAME): AwsS3Info
0 ignored issues
show
Bug introduced by
The constant Spiral\Tests\Storage\Tra...ilderTrait::SERVER_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
25
    {
26
        return new AwsS3Info($name, $this->buildAwsS3ServerDescription());
0 ignored issues
show
Bug introduced by
It seems like $name can also be of type null; however, parameter $name of Spiral\Storage\Config\DT...wsS3Info::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

26
        return new AwsS3Info(/** @scrutinizer ignore-type */ $name, $this->buildAwsS3ServerDescription());
Loading history...
27
    }
28
29
    protected function buildAwsS3ServerDescription(): array
30
    {
31
        return [
32
            AwsS3Info::ADAPTER_KEY => AwsS3V3Adapter::class,
33
            AwsS3Info::OPTIONS_KEY => [
34
                AwsS3Info::BUCKET_KEY => 'debugBucket',
35
                AwsS3Info::CLIENT_KEY => $this->getAwsS3Client(),
36
            ],
37
        ];
38
    }
39
40
    protected function getAwsS3Client(): S3Client
41
    {
42
        return new S3Client([
43
            'credentials' => new Credentials('someKey', 'someSecret'),
44
            'version' => 'latest',
45
            'region' => 'west',
46
        ]);
47
    }
48
49
    protected function getAwsS3VisibilityOption(): array
50
    {
51
        return [
52
            AwsS3Info::CLASS_KEY => PortableVisibilityConverter::class,
53
            AwsS3Info::OPTIONS_KEY => [
54
                AwsS3Info::VISIBILITY_KEY => Visibility::PUBLIC,
55
            ]
56
        ];
57
    }
58
}
59