Completed
Pull Request — master (#1)
by Albin
01:57
created

AwsS3PresignedUrlResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 4
1
<?php
2
3
namespace Gaufrette\Extras\Resolvable\Resolver;
4
5
use Aws\S3\S3Client;
6
use Gaufrette\Extras\Resolvable\ResolverInterface;
7
8
class AwsS3PresignedUrlResolver implements ResolverInterface
9
{
10
    /** @var S3Client */
11
    private $service;
12
13
    /** @var string */
14
    private $bucket;
15
16
    /** @var string */
17
    private $baseDir;
18
19
    /** @var \DateTimeInterface */
20
    private $expiresAt;
21
22
    public function __construct(S3Client $service, $bucket, $baseDir, \DateTimeInterface $expiresAt)
23
    {
24
        $this->service   = $service;
25
        $this->bucket    = $bucket;
26
        $this->baseDir   = trim($baseDir, '/');
27
        $this->expiresAt = $expiresAt;
28
    }
29
30
    /**
31
     * Resolves given object path into presigned request URI.
32
     *
33
     * @param string $path
34
     *
35
     * @return (string) \Psr\Http\Message\UriInterface
36
     */
37
    public function resolve($path)
38
    {
39
        $command = $this->service->getCommand('GetObject', [
40
            'Bucket' => $this->bucket,
41
            'Key'    => $this->computePath($path),
42
        ]);
43
44
        return (string) $this->service->createPresignedRequest($command, $this->expiresAt)->getUri();
0 ignored issues
show
Documentation introduced by
$this->expiresAt is of type object<DateTimeInterface>, but the function expects a integer|string|object<DateTime>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
    }
46
47
    /**
48
     * Appends baseDir to $key.
49
     *
50
     * @param string $key
51
     *
52
     * @return string
53
     */
54
    private function computePath($key)
55
    {
56
        return ltrim($this->baseDir . '/' . ltrim($key, '/'), '/');
57
    }
58
}
59