Completed
Push — master ( f9ded0...b13d5b )
by John
02:58 queued 01:00
created

JSONResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0
ccs 9
cts 9
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAsDataStream() 0 4 1
A getMIMEType() 0 4 1
A getResponseData() 0 4 1
1
<?php
2
namespace LunixREST\APIResponse;
3
4
use Psr\Http\Message\StreamInterface;
5
6
/**
7
 * Class JSONResponse
8
 * @package LunixREST\APIResponse
9
 */
10
class JSONResponse implements APIResponse
11
{
12
    /**
13
     * @var null|object|array
14
     */
15
    public $data;
16
17 6
    public function __construct($data)
18
    {
19 6
        $this->data = $data;
20 6
    }
21
22
    /**
23
     * @return StreamInterface
24
     */
25 1
    public function getAsDataStream(): StreamInterface
26
    {
27 1
        return \GuzzleHttp\Psr7\Stream_for(json_encode($this->data));
28
    }
29
30 1
    public function getMIMEType(): string
31
    {
32 1
        return 'application/json';
33
    }
34
35
    /**
36
     * @return null|object|array
37
     */
38 1
    public function getResponseData()
39
    {
40 1
        return $this->data;
41
    }
42
}
43