Completed
Pull Request — master (#427)
by Anton
06:09
created

Rest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
dl 0
loc 48
ccs 19
cts 20
cp 0.95
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
B prepareRequest() 0 24 5
A prepareParams() 0 10 1
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