Passed
Push — master ( d73f09...6d4625 )
by Radu
03:19
created

Helper::getRequestHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace ParcelValue\Api;
3
4
use WebServCo\Api\JsonApi\Document;
5
use WebServCo\Framework\Http\Method;
6
7
final class Helper
8
{
9
    protected $logger;
10
    protected $curlBrowser;
11
12
    public function __construct(
13
        \WebServCo\Framework\Interfaces\LoggerInterface $logger,
14
        $environment //\WebServCo\Framework\Environment
15
    ) {
16
        $this->logger = $logger;
17
        $this->curlBrowser = new \WebServCo\Framework\CurlBrowser($this->logger);
18
        if (\WebServCo\Framework\Environment::ENV_DEV == $environment) {
19
            $this->curlBrowser->setSkipSSlVerification(true);
20
        }
21
        $this->curlBrowser->setRequestHeader('Accept', Document::CONTENT_TYPE);
22
    }
23
24
    public function getRequestHeaders()
25
    {
26
        return $this->curlBrowser->getRequestHeaders();
27
    }
28
29
    /*
30
    * @return \WebServCo\Framework\Http\Response
31
    */
32
    public function getResponse($url, $method, array $headers = [], $requestData = null)
33
    {
34
        foreach ($headers as $key => $value) {
35
            $this->curlBrowser->setRequestHeader($key, $value);
36
        }
37
        switch ($method) {
38
            case Method::POST:
39
                $this->curlBrowser->setRequestContentType(Document::CONTENT_TYPE);
40
                $this->curlBrowser->setRequestData($requestData);
41
                break;
42
            case Method::GET:
43
            case Method::HEAD:
44
                break;
45
            default:
46
                throw new \WebServCo\Framework\Exceptions\NotImplementedException('Functionality not implemented');
47
                break;
48
        }
49
        $this->curlBrowser->setMethod($method);
50
        return $this->curlBrowser->retrieve($url);
51
    }
52
}
53