Completed
Pull Request — master (#427)
by Anton
07:08 queued 04:05
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\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