Completed
Push — master ( 8b5726...2416e6 )
by Tomas
06:18
created

XmlApiResponse   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
lcom 1
cbo 1
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCode() 0 4 1
A send() 0 8 1
1
<?php
2
3
namespace Tomaj\NetteApi\Response;
4
5
use Nette\Application\IResponse as ApplicationIResponse;
6
use Nette\Http\IRequest;
7
use Nette\Http\IResponse;
8
9
class XmlApiResponse implements ApplicationIResponse
10
{
11
    /**
12
     * @var integer
13
     */
14
    private $code;
15
16
    /**
17
     * @var string
18
     */
19
    private $response = null;
20
21
    /**
22
     * Create XmlApiResponse
23
     * This class only wrap JsonResponse from Nette and add possibility
24
     * to setup response code and automaticaly set content type
25
     *
26
     * @param integer $code
27
     * @param string $data
28
     */
29 3
    public function __construct($code, $data)
30
    {
31 3
        $this->code = $code;
32 3
        $this->response = $data;
33 3
    }
34
35
    /**
36
     * Return api response http code
37
     *
38
     * @return integer
39
     */
40 3
    public function getCode()
41
    {
42 3
        return $this->code;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 3
    public function send(IRequest $httpRequest, IResponse $httpResponse)
49
    {
50 3
        $httpResponse->setContentType('text/xml');
51 3
        $httpResponse->setExpiration(false);
52 3
        $httpResponse->setCode($this->getCode());
53
54 3
        echo $this->response;
55 3
    }
56
}
57