Response   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 28
c 3
b 0
f 0
dl 0
loc 75
rs 10
wmc 13

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getBody() 0 3 1
A getParsed() 0 8 1
A getStatusCode() 0 3 1
A from() 0 3 1
A setSerializer() 0 3 1
A unSerialize() 0 8 4
A getData() 0 3 1
A getHeaders() 0 3 1
A __construct() 0 7 1
A getParsedPath() 0 3 1
1
<?php
2
3
namespace Ipag\Sdk\Http;
4
5
use Ipag\Sdk\IO\JsonSerializer;
6
use Ipag\Sdk\IO\MutatorInterface;
0 ignored issues
show
Bug introduced by
The type Ipag\Sdk\IO\MutatorInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Ipag\Sdk\IO\SerializerInterface;
8
use Ipag\Sdk\Util\ArrayUtil;
9
10
class Response
11
{
12
    protected ?SerializerInterface $serializer;
13
    protected ?array $data;
14
    protected ?string $raw;
15
16
    protected ?array $headers;
17
18
    protected ?int $statusCode;
19
20
    protected function __construct(?SerializerInterface $serializer, ?string $body, ?array $headers, ?int $statusCode)
21
    {
22
        $this->raw = $body;
23
        $this->serializer = $serializer;
24
        $this->data = null;
25
        $this->headers = $headers;
26
        $this->statusCode = $statusCode;
27
    }
28
29
    public function unSerialize(): self
30
    {
31
        if (empty($this->raw) || gettype(json_decode($this->raw)) === 'string')
32
            $this->data = ['data' => $this->raw];
33
        else
34
            $this->data = $this->serializer ? $this->serializer->unserialize($this->raw) : null;
35
36
        return $this;
37
    }
38
39
    public function getParsed(): ?array
40
    {
41
        $this->unSerialize();
42
43
        return [
44
            'data' => $this->data,
45
            'headers' => $this->headers,
46
            'statusCode' => $this->statusCode
47
        ];
48
    }
49
50
    public function getParsedPath(string $dotNotation, $default = null)
51
    {
52
        return ArrayUtil::get('data.' . $dotNotation, $this->getParsed(), $default);
53
    }
54
55
    public function getBody(): ?string
56
    {
57
        return $this->raw;
58
    }
59
60
    public function getHeaders(): ?array
61
    {
62
        return $this->headers;
63
    }
64
65
    public function getStatusCode(): ?int
66
    {
67
        return $this->statusCode;
68
    }
69
70
    public function getData(): ?array
71
    {
72
        return $this->data;
73
    }
74
75
    public function setSerializer(?SerializerInterface $serializer): void
76
    {
77
        $this->serializer = $serializer;
78
    }
79
80
    //
81
82
    public static function from(?string $data, ?array $headers = null, ?int $statusCode = null): self
83
    {
84
        return new static(null, $data, $headers, $statusCode);
85
    }
86
}