Completed
Pull Request — master (#61)
by Michal
08:40
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 getCode() 0 4 1
A __construct() 0 5 1
A send() 0 8 2
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