Completed
Pull Request — master (#61)
by Michal
06:56
created

TextApiResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 40
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCode() 0 4 1
A send() 0 8 2
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