Action   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A options() 0 4 1
A run() 0 13 2
1
<?php
2
3
namespace yrc\rest;
4
5
use yii\web\HttpException;
6
use yii\helpers\ArrayHelper;
7
use Yii;
8
use ReflectionProperty;
9
use ReflectionClass;
10
11
abstract class Action extends \yii\base\Action
12
{
13
    /**
14
     * The access control list for this endpoint
15
     * @var array
16
     */
17
    public $acl;
18
19
    /**
20
     * Action runner
21
     *
22
     * @param mixed $id
23
     * @param array $args
24
     * @return mixed
25
     * @throws HttpException
26
     */
27
    public function run($id = null, array $args = [])
28
    {
29
        $method = strtolower(Yii::$app->request->method);
30
        
31
        // Make sure the method exists before trying to call it
32
        if (method_exists(get_called_class(), $method)) {
33
            return $this->$method(\array_merge(['id' => $id], $args));
34
        }
35
36
        // Return a 405 if the method isn't implemented
37
        // When coupled with RestController, this should _never_ get called
38
        // But this is the correct response if for some reason it isn't
39
        throw new HttpException(405);
40
    }
41
42
    /**
43
     * HTTP Options defaults
44
     * @param array $params
45
     * @return void
46
     */
47
    public function options(array $params = [])
48
    {
49
        Yii::$app->response->statusCode = 204;
50
        return;
51
    }
52
}
53