Completed
Push — master ( 30603a...da99bb )
by Samuel
06:18
created

BaseHandler::getValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 2
eloc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Kelemen\ApiNette\Handler;
4
5
use Nette\Application\IResponse;
6
use Nette\Http\Request;
7
use Nette\Http\Response;
8
9
abstract class BaseHandler
10
{
11
    /** @var array      Values validated by validator. Doesn't contains all input values! */
12
    protected $values;
13
14
    /**
15
     * Get validated value or default if key is not set (for optional values)
16
     * @param string $key
17
     * @param string $default
18
     * @return string
19
     */
20
    protected function getValue($key, $default = null)
21
    {
22
        return isset($this->values[$key]) ? $this->values[$key] : $default;
23
    }
24
25
    /**
26
     * @param array $values
27
     */
28 6
    public function setValidatedValues(array $values)
29
    {
30 6
        $this->values = $values;
31 6
    }
32
33
    /**
34
     * Validate input
35
     * @return array
36
     */
37 6
    public function validate()
38
    {
39 6
        return [];
40
    }
41
42
    /**
43
     * @param Request $request
44
     * @param Response $response
45
     * @param callable $next
46
     * @return IResponse
47
     */
48
    abstract public function __invoke(Request $request, Response $response, callable $next);
49
}
50