Response   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 75%

Importance

Changes 6
Bugs 0 Features 2
Metric Value
c 6
b 0
f 2
dl 0
loc 36
ccs 9
cts 12
cp 0.75
rs 10
wmc 4
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDataContent() 0 9 2
A create() 0 4 1
A setNotFound() 0 4 1
1
<?php
2
namespace JayaCode\Framework\Core\Http;
3
4
use Symfony\Component\HttpFoundation\Response as BaseResponse;
5
6
class Response extends BaseResponse
7
{
8
    /**
9
     * if content is an array, then convert to json
10
     * @param mixed $content
11
     */
12 6
    public function setDataContent($content)
13
    {
14 6
        if (is_array($content)) {
15 3
            $this->headers->set('Content-Type', 'application/json');
16 3
            $content = json_encode($content);
17 3
        }
18
19 6
        $this->setContent($content);
20 6
    }
21
22
    /**
23
     * @param mixed $content The response content, see setContent()
24
     * @param int   $status  The response status code
25
     * @param array $headers An array of response headers
26
     *
27
     * @return Response
28
     */
29 6
    public static function create($content = '', $status = 200, $headers = array())
30
    {
31 6
        return new static($content, $status, $headers);
32
    }
33
34
    /**
35
     * Setup response 404
36
     */
37
    public function setNotFound()
38
    {
39
        $this->setStatusCode(404);
40
    }
41
}
42