SixConnexResponse::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
4
namespace LaravelSixConnex;
5
6
use Illuminate\Http\Client\Response;
7
use Illuminate\Support\Collection;
8
9
/**
10
 * Class SixConnexResponse
11
 *
12
 * @method string body()
13
 */
14
class SixConnexResponse
15
{
16
    protected Response $raw;
17
18
    protected ?Collection $apicallsetoutput = null;
19
20
    /**
21
     * SixConnexResponse constructor.
22
     *
23
     * @param Response $rawResponse
24
     */
25 4
    public function __construct(Response $rawResponse)
26
    {
27 4
        $this->raw = $rawResponse;
28
    }
29
30
    /**
31
     * @return Response
32
     */
33 1
    public function getRawResponse(): Response
34
    {
35 1
        return $this->raw;
36
    }
37
38
    /**
39
     * @return  Collection
40
     */
41 1
    public function outputCollection(): Collection
42
    {
43 1
        if (!$this->apicallsetoutput) {
44 1
            $this->apicallsetoutput = $this->raw
45 1
                ->collect('apicallsetoutput')
46 1
                ->map(fn ($body) => new SixConnexOutput($body));
47
        }
48
49 1
        return $this->apicallsetoutput;
50
    }
51
52
    /**
53
     * @return  SixConnexOutput
54
     */
55 1
    public function outputFirst(): SixConnexOutput
56
    {
57 1
        return $this->outputCollection()->first();
58
    }
59
60
    /**
61
     * Dynamically proxy other methods to the underlying response.
62
     *
63
     * @param string $method
64
     * @param array $parameters
65
     *
66
     * @return mixed
67
     */
68 1
    public function __call($method, $parameters)
69
    {
70 1
        return $this->raw->{$method}(...$parameters);
71
    }
72
}
73