Passed
Pull Request — master (#407)
by Kirill
11:08 queued 03:58
created

AwsS3Info   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 58
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getVisibilityConverter() 0 5 2
A getClient() 0 3 1
A constructSpecific() 0 4 2
1
<?php
2
3
/**
4
 * This file is part of Spiral Framework package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Storage\Config\DTO\FileSystemInfo\Aws;
13
14
use Spiral\Storage\Config\DTO\FileSystemInfo\FileSystemInfo;
15
use Spiral\Storage\Config\DTO\FileSystemInfo\SpecificConfigurableFileSystemInfo;
16
use Spiral\Storage\Resolver\AwsS3Resolver;
17
18
class AwsS3Info extends FileSystemInfo implements SpecificConfigurableFileSystemInfo
19
{
20
    public const BUCKET_KEY = 'bucket';
21
    public const CLIENT_KEY = 'client';
22
    public const PATH_PREFIX_KEY = 'path-prefix';
23
24
    protected const FILE_SYSTEM_INFO_TYPE = 'awsS3';
25
26
    protected const REQUIRED_OPTIONS = [
27
        self::BUCKET_KEY => self::STRING_TYPE,
28
        self::CLIENT_KEY => self::MIXED_TYPE,
29
    ];
30
31
    protected const ADDITIONAL_OPTIONS = [
32
        self::PATH_PREFIX_KEY => self::STRING_TYPE,
33
        self::VISIBILITY_KEY => self::ARRAY_TYPE,
34
    ];
35
36
    /**
37
     * @var string
38
     */
39
    protected $resolver = AwsS3Resolver::class;
40
41
    /**
42
     * @var AwsVisibilityConverter|null
43
     */
44
    protected $visibilityConverter = null;
45
46
    /**
47
     * @inheritDoc
48
     */
49
    public function constructSpecific(array $info): void
50
    {
51
        if ($this->hasOption(static::VISIBILITY_KEY)) {
52
            $this->visibilityConverter = new AwsVisibilityConverter($this->getOption(static::VISIBILITY_KEY));
0 ignored issues
show
Bug introduced by
It seems like $this->getOption(static::VISIBILITY_KEY) can also be of type null; however, parameter $info of Spiral\Storage\Config\DT...onverter::__construct() does only seem to accept array, 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

52
            $this->visibilityConverter = new AwsVisibilityConverter(/** @scrutinizer ignore-type */ $this->getOption(static::VISIBILITY_KEY));
Loading history...
53
        }
54
    }
55
56
    /**
57
     * Get prepared visibility converter
58
     *
59
     * @return mixed|null
60
     */
61
    public function getVisibilityConverter()
62
    {
63
        return $this->visibilityConverter instanceof AwsVisibilityConverter
64
            ? $this->visibilityConverter->getConverter()
65
            : null;
66
    }
67
68
    /**
69
     * Get S3 client
70
     *
71
     * @return mixed|null
72
     */
73
    public function getClient()
74
    {
75
        return $this->getOption(static::CLIENT_KEY);
76
    }
77
}
78