SignAzureUpload   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 45
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getSasUrl() 0 25 4
1
<?php
2
3
namespace A17\Twill\Services\Uploader;
4
5
use DateTime;
6
use DateTimeZone;
7
use Illuminate\Config\Repository as Config;
8
use Illuminate\Http\Request;
9
use MicrosoftAzure\Storage\Blob\BlobSharedAccessSignatureHelper;
10
11
class SignAzureUpload
12
{
13
    /**
14
     * @var Config
15
     */
16
    protected $config;
17
18
    /**
19
     * @var Config
20
     */
21
    protected $blobSharedAccessSignatureHelper;
22
23
    /**
24
     * @param Config $config
25
     */
26
    public function __construct(Config $config)
27
    {
28
        $this->config = $config;
29
    }
30
31
    public function getSasUrl(Request $request, SignUploadListener $listener, $disk = 'libraries')
32
    {
33
        try {
34
            $blobUri = $request->input('bloburi');
35
            $method = $request->input('_method');
36
            $permissions = '' ;
37
            if (strtolower($method) === 'put') {
38
                $permissions = 'w';
39
            } else if (strtolower($method) === 'delete') {
40
                $permissions = 'd';
41
            }
42
43
            $this->blobSharedAccessSignatureHelper = new BlobSharedAccessSignatureHelper(
0 ignored issues
show
Documentation Bug introduced by
It seems like new MicrosoftAzure\Stora...ks.' . $disk . '.key')) of type MicrosoftAzure\Storage\B...edAccessSignatureHelper is incompatible with the declared type Illuminate\Config\Repository of property $blobSharedAccessSignatureHelper.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
44
                $this->config->get('filesystems.disks.' . $disk . '.name'),
45
                $this->config->get('filesystems.disks.' . $disk . '.key')
46
            );
47
48
            $now = new DateTime("now", new DateTimeZone("UTC"));
49
            $expire = $now->modify('+15 min');
50
51
            $path = $this->config->get('filesystems.disks.' . $disk .'.container') . str_replace(azureEndpoint($disk), '', $blobUri);
52
            $sasUrl = $blobUri . '?' . $this->blobSharedAccessSignatureHelper->generateBlobServiceSharedAccessSignatureToken('b', $path, $permissions, $expire);
53
            return $listener->uploadIsSigned($sasUrl, false);
54
        } catch (\Exception $e) {
55
            return $listener->uploadIsNotValid();
56
        }
57
    }
58
}
59