Completed
Push — master ( 604a2f...9beb61 )
by Anton
10s
created

Rest::run()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 11
c 0
b 0
f 0
nc 16
nop 0
dl 0
loc 22
rs 8.6737
ccs 0
cts 17
cp 0
crap 30
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Controller\Mapper;
12
13
use Bluz\Http\RequestMethod;
14
15
/**
16
 * Rest
17
 *
18
 * @package  Bluz\Rest
19
 * @author   Anton Shevchuk
20
 */
21
class Rest extends AbstractMapper
22
{
23
    /**
24
     * Process request
25
     *
26
     * @return void
27
     */
28 9
    protected function prepareRequest()
29
    {
30 9
        parent::prepareRequest();
31
32 9
        $params = $this->params;
33
34 9
        if (count($params)) {
35 2
            $primaryKeys = $this->crud->getPrimaryKey();
36 2
            $primaryValues = explode('-', array_shift($params));
37
38 2
            $this->primary = array_combine($primaryKeys, $primaryValues);
39
        }
40 9
        if (count($params)) {
41 1
            $this->relation = array_shift($params);
42
        }
43 9
        if (count($params)) {
44 1
            $this->relationId = array_shift($params);
45
        }
46
47
        // OPTIONS
48 9
        if (RequestMethod::OPTIONS === $this->method) {
49
            $this->data = array_keys($this->map);
50
        }
51 9
    }
52
53
    /**
54
     * Prepare params
55
     *
56
     * @return array
57
     */
58 7
    protected function prepareParams(): array
59
    {
60
        return [
61 7
            'crud' => $this->crud,
62 7
            'primary' => $this->primary,
63 7
            'data' => $this->data,
64 7
            'relation' => $this->relation,
65 7
            'relationId' => $this->relationId
66
        ];
67
    }
68
}
69