Completed
Pull Request — master (#267)
by
unknown
08:50
created

Transport   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 6 1
A _setHeaders() 0 15 2
1
<?php
2
namespace QiniuRtc;
3
4
use \QiniuRtc\Utils;
5
use \QiniuRtc\HttpRequest;
6
7
final class Transport
8
{
9
    private $_mac;
10
11
    public function __construct($mac)
12
    {
13
        $this->_mac = $mac;
14
    }
15
16
    public function send($method, $url, $body = null)
17
    {
18
        $headers = $this->_setHeaders($method, $url, $body);
19
        $response = HttpRequest::send($method, $url, $body, $headers);
20
        return $response->body;
0 ignored issues
show
Documentation introduced by
The property $body is declared private in QiniuRtc\HttpResponse. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
21
    }
22
23
    private function _setHeaders($method, $url, $body = null)
24
    {
25
        if ($method != HttpRequest::GET) {
26
            $cType = 'application/json';
27
        } else {
28
            $cType = null;
29
        }
30
        $macToken = $this->_mac->MACToken($method, $url, $cType, $body);
31
        $ua = Utils::getUserAgent(Config::SDK_USER_AGENT, Config::SDK_VERSION);
32
        return array(
33
            'Content-Type'  => $cType,
34
            'User-Agent'    => $ua,
35
            'Authorization' => $macToken,
36
        );
37
    }
38
}
39