BaseHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 41
ccs 5
cts 7
cp 0.7143
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 4 2
A setValidatedValues() 0 4 1
A validate() 0 4 1
__invoke() 0 1 ?
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