Passed
Push — master ( 1ab0cb...c16903 )
by Radu
01:12
created

ShipmentsCommand::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
namespace ParcelValue\ApiClient\Domain\Shipments;
3
4
use WebServCo\Framework\CliResponse;
5
6
final class ShipmentsCommand extends \ParcelValue\ApiClient\AbstractController
7
{
8
    protected $logger;
9
    protected $curlBrowser;
10
11
    protected $httpResponse;
12
    protected $responseStatus;
13
    protected $responseContent;
14
    protected $responseHeaders;
15
16
    public function __construct()
17
    {
18
        parent::__construct();
19
20
        $this->repository = new ShipmentsRepository($this->outputLoader);
21
22
        $this->logger = new \WebServCo\Framework\FileLogger(
23
            __FUNCTION__,
24
            sprintf('%svar/log/', $this->data('path/project', '')),
25
            $this->request()
26
        );
27
        $this->curlBrowser = new \WebServCo\Framework\CurlBrowser($this->logger);
28
        if (\WebServCo\Framework\Environment::ENV_DEV == $this->config()->getEnv()) {
29
            $this->curlBrowser->setSkipSSlVerification(true);
30
        }
31
        $this->curlBrowser->setRequestHeader('Accept', \WebServCo\Api\JsonApi\Structure::CONTENT_TYPE);
32
    }
33
34
    public function create($clientId, $clientKey, $serverKey)
35
    {
36
        $this->outputCli(__METHOD__, true);
37
38
        $url = sprintf(
39
            '%s%s/shipments',
40
            $this->config()->get('app/api/url'),
41
            $this->config()->get('app/api/version')
42
        );
43
44
        $jwt = \ParcelValue\Api\AuthenticationToken::generate($clientId, $clientKey, $serverKey);
45
        $this->curlBrowser->setRequestHeader('Authorization', sprintf('Bearer %s', $jwt));
46
47
        $postData = [];
48
49
        $this->outputCli('---', true);
50
        $this->outputCli('REQUEST', true);
51
        $this->outputCli(sprintf('POST %s', $url), true);
52
        $this->outputCli(sprintf('Headers: %s', print_r($this->curlBrowser->getRequestHeaders(), true)), true);
0 ignored issues
show
Bug introduced by
The method getRequestHeaders() does not exist on WebServCo\Framework\CurlBrowser. Did you maybe mean setRequestHeader()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        $this->outputCli(sprintf('Headers: %s', print_r($this->curlBrowser->/** @scrutinizer ignore-call */ getRequestHeaders(), true)), true);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
        $this->outputCli(sprintf('POST data: %s', print_r($postData, true)), true);
54
55
        $this->httpResponse = $this->curlBrowser->post($url, $postData);
56
        $this->responseStatus = $this->httpResponse->getStatus();
57
        $this->responseHeaders = $this->httpResponse->getHeaders();
58
        $this->responseContent = $this->httpResponse->getContent();
59
60
        $this->outputCli('---', true);
61
        $this->outputCli('RESPONSE', true);
62
        $this->outputCli(sprintf('Status code: %s', $this->responseStatus), true);
63
        $this->outputCli(sprintf('Headers: %s', print_r($this->responseHeaders, true)), true);
64
        $this->outputCli(sprintf('Content: %s', print_r(json_decode($this->responseContent), true)), true);
65
        //$this->outputCli(var_export($this->responseStatus), true);
66
        //$this->outputCli(var_export($this->responseHeaders), true);
67
        //$this->outputCli(var_export($this->responseContent), true);
68
69
        //$this->outputCli('', true);
70
        return new CliResponse('', true);
71
    }
72
}
73