Issues (49)

app/Services/S3Service.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace App\Services;
4
5
use App\Models\Song;
6
use Aws\S3\S3ClientInterface;
7
use Illuminate\Cache\Repository as Cache;
8
9
class S3Service implements ObjectStorageInterface
10
{
11
    private $s3Client;
12
    private $cache;
13
14 14
    public function __construct(?S3ClientInterface $s3Client, Cache $cache)
15
    {
16 14
        $this->s3Client = $s3Client;
17 14
        $this->cache = $cache;
18 14
    }
19
20 1
    public function getSongPublicUrl(Song $song): string
21
    {
22
        return $this->cache->remember("OSUrl/{$song->id}", 60, function () use ($song): string {
23
            $cmd = $this->s3Client->getCommand('GetObject', [
0 ignored issues
show
The method getCommand() does not exist on null. ( Ignorable by Annotation )

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

23
            /** @scrutinizer ignore-call */ 
24
            $cmd = $this->s3Client->getCommand('GetObject', [

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
                'Bucket' => $song->s3_params['bucket'],
25
                'Key' => $song->s3_params['key'],
26
            ]);
27
28
            // Here we specify that the request is valid for 1 hour.
29
            // We'll also cache the public URL for future reuse.
30
            $request = $this->s3Client->createPresignedRequest($cmd, '+1 hour');
31
            $url = (string) $request->getUri();
32
33
            return $url;
34 1
        });
35
    }
36
}
37