Response::array()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Erykai\Response;
4
5
/**
6
 * return data in json, array and object
7
 */
8
class Response extends Resource
9
{
10
    /**
11
     * @param object $data
12
     * @return $this
13
     */
14
    public function data(object $data): static
15
    {
16
        $data = array_filter((array) $data);
17
        $data = (object) $data;
18
        $this->setResponse($data);
19
        return $this;
20
    }
21
    /**
22
     * @return string
23
     */
24
    public function json(): string
25
    {
26
        header('Content-Type: application/json; charset=utf-8');
27
        return json_encode($this->getResponse());
28
    }
29
    /**
30
     * @return array
31
     */
32
    public function array(): array
33
    {
34
        return json_decode(json_encode($this->getResponse()));
35
    }
36
37
    /**
38
     * @return object
39
     */
40
    public function object(): object
41
    {
42
        return $this->getResponse();
43
    }
44
}