Passed
Pull Request — master (#407)
by Kirill
09:17 queued 03:56
created

S3SignedResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
dl 0
loc 51
rs 10
c 1
b 0
f 1
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A createCommand() 0 5 1
A resolve() 0 10 1
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\Distribution\Resolver;
13
14
use Aws\CommandInterface;
15
use Aws\S3\S3ClientInterface;
16
use Psr\Http\Message\UriInterface;
17
use Spiral\Distribution\Internal\DateTimeIntervalFactoryInterface;
18
19
/**
20
 * @psalm-import-type DateIntervalFormat from DateTimeIntervalFactoryInterface
21
 * @see DateTimeIntervalFactoryInterface
22
 */
23
class S3SignedResolver extends ExpirationAwareResolver
24
{
25
    /**
26
     * @var S3ClientInterface
27
     */
28
    private $client;
29
30
    /**
31
     * @var string
32
     */
33
    private $bucket;
34
35
    /**
36
     * @param S3ClientInterface $client
37
     * @param string $bucket
38
     */
39
    public function __construct(S3ClientInterface $client, string $bucket)
40
    {
41
        $this->client = $client;
42
        $this->bucket = $bucket;
43
44
        parent::__construct();
45
    }
46
47
    /**
48
     * @param string $file
49
     * @param DateIntervalFormat|null $expiration
0 ignored issues
show
Bug introduced by
The type Spiral\Distribution\Resolver\DateIntervalFormat 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...
50
     * @return UriInterface
51
     * @throws \Exception
52
     */
53
    public function resolve(string $file, $expiration = null): UriInterface
54
    {
55
        $command = $this->createCommand($file);
56
57
        $request = $this->client->createPresignedRequest(
58
            $command,
59
            $this->getExpirationDateTime($expiration)
60
        );
61
62
        return $request->getUri();
63
    }
64
65
    /**
66
     * @param string $file
67
     * @return CommandInterface
68
     */
69
    private function createCommand(string $file): CommandInterface
70
    {
71
        return $this->client->getCommand('GetObject', [
72
            'Bucket' => $this->bucket,
73
            'Key'    => $file,
74
        ]);
75
    }
76
}
77