Completed
Pull Request — master (#363)
by Anton
05:32
created

Rest::run()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
nc 16
nop 0
dl 0
loc 23
ccs 0
cts 18
cp 0
crap 30
rs 8.5906
c 1
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
/**
10
 * @namespace
11
 */
12
namespace Bluz\Controller\Mapper;
13
14
use Bluz\Application\Exception\ForbiddenException;
15
use Bluz\Application\Exception\NotImplementedException;
16
use Bluz\Proxy\Response;
17
18
/**
19
 * Rest
20
 *
21
 * @package  Bluz\Rest
22
 * @author   Anton Shevchuk
23
 */
24
class Rest extends AbstractMapper
25
{
26
    /**
27
     * Run REST controller
28
     * @return mixed
29
     * @throws ForbiddenException
30
     * @throws NotImplementedException
31
     */
32
    public function run()
33
    {
34
        $params = $this->params;
35
36
        if (sizeof($params)) {
37
            $this->primary = explode('-', array_shift($params));
38
        }
39
        if (sizeof($params)) {
40
            $this->relation = array_shift($params);
41
        }
42
        if (sizeof($params)) {
43
            $this->relationId = array_shift($params);
44
        }
45
46
        // OPTIONS
47
        if ('OPTIONS' == $this->method) {
48
            Response::setHeader('Allow', join(',', array_keys($this->map)));
49
            return null;
50
        }
51
52
        // dispatch controller
53
        return parent::run();
54
    }
55
}
56