Completed
Pull Request — master (#466)
by Anton
12:30 queued 10:37
created

Rest::prepareParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 9
    protected function prepareRequest(): void
24
    {
25 9
        parent::prepareRequest();
26
27 9
        $params = $this->params;
28
29 9
        if (\count($params)) {
30 2
            $primaryKeys = $this->crud->getPrimaryKey();
31
32 2
            $primaryValues = explode('-', array_shift($params), \count($primaryKeys));
33
34 2
            $this->primary = array_combine($primaryKeys, $primaryValues);
35
        }
36 9
        if (\count($params)) {
37 1
            $this->relation = array_shift($params);
38
        }
39 9
        if (\count($params)) {
40 1
            $this->relationId = array_shift($params);
41
        }
42
43
        // OPTIONS
44 9
        if (RequestMethod::OPTIONS === $this->method) {
45
            $this->data = array_keys($this->map);
46
        }
47 9
    }
48
49 7
    protected function prepareParams(): array
50
    {
51
        return [
52 7
            'crud' => $this->crud,
53 7
            'primary' => $this->primary,
54 7
            'data' => $this->data,
55 7
            'relation' => $this->relation,
56 7
            'relationId' => $this->relationId
57
        ];
58
    }
59
}
60