Completed
Pull Request — master (#61)
by Michal
08:40
created

TextApiResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Tomaj\NetteApi\Response;
4
5
use Nette\Application\UI\ITemplate;
6
use Nette\Http\IRequest;
7
use Nette\Http\IResponse;
8
use Nette\SmartObject;
9
10
class TextApiResponse implements ResponseInterface
11
{
12
    use SmartObject;
13
14
    /** @var int */
15
    private $code;
16
17
    /** @var mixed */
18
    private $data;
19
20
    /**
21
     * @param int $code
22
     * @param mixed $data
23
     */
24 3
    public function __construct(int $code, $data)
25
    {
26 3
        $this->code = $code;
27 3
        $this->data = $data;
28 3
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 3
    public function getCode(): int
34
    {
35 3
        return $this->code;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 3
    public function send(IRequest $httpRequest, IResponse $httpResponse): void
42
    {
43 3
        if ($this->data instanceof ITemplate) {
44
            $this->data->render();
45
        } else {
46 3
            echo $this->data;
47
        }
48 3
    }
49
}
50