Response   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 35
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A json() 0 4 1
A array() 0 3 1
A object() 0 3 1
A data() 0 6 1
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
}