BaseHandler::getValue()   A
last analyzed

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 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Kelemen\ApiNette\Handler;
4
5
use Kelemen\ApiNette\Response\ApiResponse;
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 array_key_exists($key, $this->values) ? $this->values[$key] : $default;
23
    }
24
25
    /**
26
     * @param array $values
27
     */
28 16
    public function setValidatedValues(array $values)
29
    {
30 16
        $this->values = $values;
31 16
    }
32
33
    /**
34
     * Validate input
35
     * @return array
36
     */
37 16
    public function validate()
38
    {
39 16
        return [];
40
    }
41
42
    /**
43
     * @param Request $request
44
     * @param Response $response
45
     * @param callable $next
46
     * @return ApiResponse
47
     */
48
    abstract public function __invoke(Request $request, Response $response, callable $next);
49
}
50