Completed
Pull Request — master (#61)
by Michal
06:56
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
declare(strict_types=1);
4
5
namespace Tomaj\NetteApi\Response;
6
7
use Nette\Application\UI\ITemplate;
8
use Nette\Http\IRequest;
9
use Nette\Http\IResponse;
10
use Nette\SmartObject;
11
12
class TextApiResponse implements ResponseInterface
13
{
14
    use SmartObject;
15
16
    /** @var int */
17
    private $code;
18
19
    /** @var mixed */
20
    private $data;
21
22
    /**
23
     * @param int $code
24
     * @param mixed $data
25
     */
26 6
    public function __construct(int $code, $data)
27
    {
28 6
        $this->code = $code;
29 6
        $this->data = $data;
30 6
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 3
    public function getCode(): int
36
    {
37 3
        return $this->code;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 3
    public function send(IRequest $httpRequest, IResponse $httpResponse): void
44
    {
45 3
        if ($this->data instanceof ITemplate) {
46
            $this->data->render();
47
        } else {
48 3
            echo $this->data;
49
        }
50 3
    }
51
}
52