Test Failed
Push — master ( 7e1cd8...ca4e13 )
by Stephen
01:07 queued 11s
created

s3FileUrlTemp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Illuminate\Support\Facades\Storage;
4
use Sfneal\Helpers\Aws\S3\Utils\S3;
5
6
/**
7
 * Return either an S3 file url.
8
 *
9
 * @param string $path
10
 * @param bool $temp
11
 * @param DateTimeInterface|null $expiration
12
 * @return string
13
 */
14
function s3FileURL(string $path, bool $temp = true, DateTimeInterface $expiration = null): string
15
{
16
    // todo: refactor to `fileUrl()`
17
    if ($temp) {
18
        return (new S3($path))->urlTemp($expiration);
19
    } else {
20
        return (new S3($path))->url();
21
    }
22
}
23
24
/**
25
 * Return a temporary S3 file url.
26
 *
27
 * @param string $path
28
 * @param DateTimeInterface|null $expiration
29
 * @return string
30
 */
31
function s3FileUrlTemp(string $path, DateTimeInterface $expiration = null): string
32
{
33
    return (new S3($path))->urlTemp($expiration);
34
}
35
36
/**
37
 * Determine if an S3 file exists.
38
 *
39
 * @param string $s3_key
40
 * @return bool
41
 */
42
function s3Exists(string $s3_key): bool
43
{
44
    return Storage::disk('s3')->exists($s3_key);
45
}
46