Storage   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 30
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A download() 0 4 1
A upload() 0 15 1
A url() 0 4 1
1
<?php
2
3
namespace Basis;
4
5
use GuzzleHttp\Client;
6
7
class Storage
8
{
9
    public $hostname = 'storage';
10
11
    public function download(string $hash)
12
    {
13
        return file_get_contents($this->url($hash));
14
    }
15
16
    public function upload(string $filename, $contents) : string
17
    {
18
        $client = new Client();
19
        $response = $client->request('POST', "http://$this->hostname/storage/upload", [
20
            'multipart' => [
21
                [
22
                    'name' => 'file',
23
                    'filename' => $filename,
24
                    'contents' => $contents,
25
                ],
26
            ]
27
        ]);
28
29
        return json_decode($response->getBody())->hash[0];
30
    }
31
32
    public function url(string $hash) : string
33
    {
34
        return "http://$this->hostname/storage/get?$hash";
35
    }
36
}
37