Controller   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 41
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A verbs() 0 3 1
A behaviors() 0 19 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-rest/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-rest
7
 */
8
9
namespace flipbox\craft\rest;
10
11
use yii\filters\auth\CompositeAuth;
12
use yii\filters\ContentNegotiator;
13
use yii\filters\RateLimiter;
14
use yii\filters\VerbFilter;
15
use yii\web\Response;
16
17
/**
18
 * Controller is the base class for RESTful API controller classes.
19
 *
20
 * Controller implements the following steps in a RESTful API request handling cycle:
21
 *
22
 * 1. Resolving response format (see [[ContentNegotiator]]);
23
 * 2. Validating request method (see [[verbs()]]).
24
 * 3. Authenticating user (see [[\yii\filters\auth\AuthInterface]]);
25
 * 4. Rate limiting (see [[RateLimiter]]);
26
 *
27
 * @author Flipbox Factory <[email protected]>
28
 * @since 1.0.0
29
 */
30
class Controller extends \yii\web\Controller
31
{
32
    /**
33
     * @inheritdoc
34
     */
35
    public $enableCsrfValidation = false;
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function behaviors()
41
    {
42
        return [
43
            'contentNegotiator' => [
44
                'class' => ContentNegotiator::class,
45
                'formats' => [
46
                    'application/json' => Response::FORMAT_JSON,
47
                    'application/xml' => Response::FORMAT_XML,
48
                ],
49
            ],
50
            'verbFilter' => [
51
                'class' => VerbFilter::class,
52
                'actions' => $this->verbs(),
53
            ],
54
            'authenticator' => [
55
                'class' => CompositeAuth::class
56
            ],
57
            'rateLimiter' => [
58
                'class' => RateLimiter::class,
59
            ],
60
        ];
61
    }
62
63
    /**
64
     * Declares the allowed HTTP verbs.
65
     * Please refer to [[VerbFilter::actions]] on how to declare the allowed verbs.
66
     * @return array the allowed HTTP verbs.
67
     */
68
    protected function verbs(): array
69
    {
70
        return [];
71
    }
72
}
73