Completed
Push — master ( 83cea8...e47c19 )
by Anton
17s queued 12s
created

Rest::prepareRequest()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5.0113

Importance

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