HttpResponse::fromArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace Ghc\Rosetta\Messages;
4
5
use GuzzleHttp\Psr7\Response;
6
7
/**
8
 * @property Response $data
9
 */
10
class HttpResponse extends Message
11
{
12
    /**
13
     * @return string
14
     */
15
    public function newData()
16
    {
17
        return new Response();
0 ignored issues
show
Bug Best Practice introduced by
The expression return new GuzzleHttp\Psr7\Response() returns the type GuzzleHttp\Psr7\Response which is incompatible with the documented return type string.
Loading history...
18
    }
19
20
    /**
21
     * Get the instance as an array.
22
     *
23
     * @return array
24
     */
25
    public function toArray()
26
    {
27
        return [
28
            'status_code' => $this->getData()->getStatusCode(),
29
            'headers'     => $this->getData()->getHeaders(),
30
            'body'        => $this->getData()->getBody(),
31
        ];
32
    }
33
34
    /**
35
     * @param array $data
36
     *
37
     * @return self
38
     */
39
    public function fromArray($data)
40
    {
41
        return $this->setData(new Response($data['status_code'], $data['headers'], $data['body']));
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function __toString()
48
    {
49
        return (string) $this->getData()->getBody();
50
    }
51
}
52