Form   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
ccs 24
cts 24
cp 1
wmc 2
lcom 1
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A upload() 0 33 2
1
<?php
2
3
namespace Upyun\Api;
4
5
use Upyun\Signature;
6
use Upyun\Util;
7
use GuzzleHttp\Client;
8
9
class Form extends Rest
10
{
11 1
    public function upload($path, $stream, $params)
12
    {
13 1
        $params['save-key'] = $path;
14 1
        $params['service'] = $this->config->serviceName;
15 1
        if (!isset($params['expiration'])) {
16 1
            $params['expiration'] = time() + 30 * 60 * 60; // 30 分钟
17 1
        }
18
19 1
        $policy = Util::base64Json($params);
20 1
        $method = 'POST';
21 1
        $signature = Signature::getBodySignature($this->config, $method, '/' . $params['service'], null, $policy);
22 1
        $client = new Client([
23 1
            'timeout' => $this->config->timeout,
24 1
        ]);
25
26 1
        $response = $client->request($method, $this->endpoint, array(
27
            'multipart' => array(
28
                array(
29 1
                    'name' => 'policy',
30 1
                    'contents' => $policy,
31 1
                ),
32
                array(
33 1
                    'name' => 'authorization',
34 1
                    'contents' => $signature,
35 1
                ),
36
                array(
37 1
                    'name' => 'file',
38 1
                    'contents' => $stream,
39
                )
40 1
            )
41 1
        ));
42 1
        return $response->getStatusCode() === 200;
43
    }
44
}
45