GetReportHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace DMT\Insolvency\Http;
4
5
use DMT\Http\Client\RequestHandler;
6
use DMT\Insolvency\Config;
7
use DMT\Insolvency\Http\Request\GetReport;
8
use DMT\Insolvency\Http\Response\GetReportResponse;
9
use DMT\Insolvency\Http\Response\GetReportResult;
10
use DMT\Insolvency\Model\Document;
11
use GuzzleHttp\Client as HttpClient;
12
use GuzzleHttp\Psr7\Request as HttpRequest;
13
use Psr\Http\Client\ClientExceptionInterface;
14
use Psr\Http\Message\RequestFactoryInterface;
15
16
/**
17
 * Class GetReportHandler
18
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
19
class GetReportHandler
20
{
21
    private Config $config;
0 ignored issues
show
Coding Style introduced by
Private member variable "config" must be prefixed with an underscore
Loading history...
22
    private RequestHandler $requestHandler;
0 ignored issues
show
Coding Style introduced by
Private member variable "requestHandler" must be prefixed with an underscore
Loading history...
23
    protected RequestFactoryInterface $requestFactory;
24
25
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $requestFactory should have a doc-comment as per coding-style.
Loading history...
26
     * GetReportHandler constructor.
27
     *
28
     * @param RequestHandler $requestHandler
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $requestHandler does not match actual variable name $config
Loading history...
29
     * @param Config $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Doc comment for parameter $config does not match actual variable name $requestHandler
Loading history...
30
     */
31 5
    public function __construct(
32
        Config $config,
33
        RequestHandler $requestHandler,
34
        RequestFactoryInterface $requestFactory
35
    ) {
36 5
        $this->config = $config;
37 5
        $this->requestHandler = $requestHandler;
38 5
        $this->requestFactory = $requestFactory;
39 5
    }
40
41
    /**
42
     * Handle http request.
43
     *
44
     * @param GetReport $request
0 ignored issues
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
45
     * @return GetReportResponse
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
46
     * @throws ClientExceptionInterface
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
47
     */
48 5
    public function handle(GetReport $request): GetReportResponse
49
    {
50 5
        $request = new HttpRequest('GET', $this->config->documentUri . $request->reportId, []);
51
52 5
        $httpResponse = $this->requestHandler->handle($request);
53
54 4
        $response = new GetReportResponse();
55 4
        $response->result = new GetReportResult();
56 4
        $response->result->report = new Document();
57 4
        $response->result->report->mime = $httpResponse->getHeaderLine('Content-Type');
58 4
        $response->result->report->document = base64_encode($httpResponse->getBody()->getContents());
59
60 4
        return $response;
61
    }
62
}
63