Completed
Pull Request — master (#427)
by Anton
06:09
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\Application\Exception\ForbiddenException;
14
use Bluz\Application\Exception\NotImplementedException;
15
use Bluz\Http\RequestMethod;
16
17
/**
18
 * Rest
19
 *
20
 * @package  Bluz\Rest
21
 * @author   Anton Shevchuk
22
 */
23
class Rest extends AbstractMapper
24
{
25
    /**
26
     * Process request
27
     *
28
     * @return void
29
     */
30 9
    protected function prepareRequest()
31
    {
32 9
        parent::prepareRequest();
33
34 9
        $params = $this->params;
35
36 9
        if (count($params)) {
37 2
            $primaryKeys = $this->crud->getPrimaryKey();
38 2
            $primaryValues = explode('-', array_shift($params));
39
40 2
            $this->primary = array_combine($primaryKeys, $primaryValues);
41
        }
42 9
        if (count($params)) {
43 1
            $this->relation = array_shift($params);
44
        }
45 9
        if (count($params)) {
46 1
            $this->relationId = array_shift($params);
47
        }
48
49
        // OPTIONS
50 9
        if (RequestMethod::OPTIONS === $this->method) {
51
            $this->data = array_keys($this->map);
52
        }
53 9
    }
54
55
    /**
56
     * Prepare params
57
     *
58
     * @return array
59
     */
60 7
    protected function prepareParams(): array
61
    {
62
        return [
63 7
            'crud' => $this->crud,
64 7
            'primary' => $this->primary,
65 7
            'data' => $this->data,
66 7
            'relation' => $this->relation,
67 7
            'relationId' => $this->relationId
68
        ];
69
    }
70
}
71