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

AwsS3Resolver::buildUrl()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 18
rs 9.9
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\Resolver;
13
14
use Spiral\Storage\Config\DTO\FileSystemInfo\Aws\AwsS3Info;
15
use Spiral\Storage\Config\DTO\FileSystemInfo\FileSystemInfoInterface;
16
17
class AwsS3Resolver extends AbstractAdapterResolver
18
{
19
    public const EXPIRES_OPTION = 'expires';
20
21
    protected const FILE_SYSTEM_INFO_CLASS = AwsS3Info::class;
22
23
    private const DEFAULT_URL_EXPIRES = '+24hours';
24
25
    /**
26
     * @var FileSystemInfoInterface|AwsS3Info
27
     */
28
    protected $fsInfo;
29
30
    /**
31
     * @inheritDoc
32
     */
33
    public function buildUrl(string $uri, array $options = [])
34
    {
35
        $s3Client = $this->fsInfo->getClient();
0 ignored issues
show
Bug introduced by
The method getClient() does not exist on Spiral\Storage\Config\DT...FileSystemInfoInterface. It seems like you code against a sub-type of Spiral\Storage\Config\DT...FileSystemInfoInterface such as Spiral\Storage\Config\DT...ystemInfo\Aws\AwsS3Info. ( Ignorable by Annotation )

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

35
        /** @scrutinizer ignore-call */ 
36
        $s3Client = $this->fsInfo->getClient();
Loading history...
36
37
        return (string)$s3Client
38
            ->createPresignedRequest(
39
                $s3Client->getCommand(
40
                    'GetObject',
41
                    [
42
                        'Bucket' => $this->fsInfo->getOption(AwsS3Info::BUCKET_KEY),
0 ignored issues
show
Bug introduced by
The method getOption() does not exist on Spiral\Storage\Config\DT...FileSystemInfoInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Spiral\Storage\Config\DT...FileSystemInfoInterface. ( Ignorable by Annotation )

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

42
                        'Bucket' => $this->fsInfo->/** @scrutinizer ignore-call */ getOption(AwsS3Info::BUCKET_KEY),
Loading history...
43
                        'Key' => $this->normalizeFilePath($uri),
44
                    ]
45
                ),
46
                array_key_exists(static::EXPIRES_OPTION, $options)
47
                    ? $options[static::EXPIRES_OPTION]
48
                    : static::DEFAULT_URL_EXPIRES
49
            )
50
            ->getUri();
51
    }
52
}
53