Completed
Pull Request — master (#2)
by Michał
01:58
created

HttpfulTransport   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sendRequest() 0 16 3
A post() 0 4 1
1
<?php
2
namespace Barenote\Transport;
3
4
use Barenote\Enum\HttpMethod;
5
use Httpful\Request;
6
use Httpful\Response;
7
8
/**
9
 * Class HttpfulTransport
10
 * @package Barenote\Transport
11
 */
12
class HttpfulTransport extends BaseTransport
13
{
14
    public function sendRequest(HttpMethod $method, string $url, string $body): Response
15
    {
16
        switch ($method) {
17
            case HttpMethod::POST():
18
                $request = $this->post($url, $body);
19
                break;
20
            default:
21
                throw new \Exception("Method not recognised");
22
        }
23
24
        if ($this->isAuthenticated()) {
25
            $request->addHeader("Authorization", "Bearer " . $this->token->getValue());
26
        }
27
28
        return $request->send();
29
    }
30
31
    /**
32
     * @param $url
33
     * @param $body
34
     * @return Request
35
     */
36
    private function post(string $url, string $body)
37
    {
38
        return Request::post($this->host . $url, $body);
39
    }
40
}