RestController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 58
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 40 1
A actions() 0 8 1
1
<?php
2
3
namespace zacksleo\yii2\oauth2\api\components;
4
5
use yii\rest\Controller;
6
use yii\helpers\ArrayHelper;
7
use zacksleo\yii2\oauth2\api\filters\ErrorToExceptionFilter;
8
use yii\filters\ContentNegotiator;
9
use yii\web\Response;
10
11
/**
12
 * Class AuthController
13
 */
14
class RestController extends Controller
15
{
16
    /**
17
     * @inheritdoc
18
     */
19
    public function behaviors()
20
    {
21
        $behaviors = ArrayHelper::merge(parent::behaviors(), [
22
            'exceptionFilter' => [
23
                'class' => ErrorToExceptionFilter::className()
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
24
            ],
25
            [
26
                'class' => ContentNegotiator::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
27
                'formats' => [
28
                    'application/json' => Response::FORMAT_JSON,
29
                ],
30
                'languages' => [
31
                    'zh-CN',
32
                    'zh-TW',
33
                    'en-US',
34
                ],
35
            ],
36
        ]);
37
        $auth = $behaviors['authenticator'];
38
        unset($behaviors['authenticator']);
39
        $behaviors['corsFilter'] = [
40
            'class' => \yii\filters\Cors::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
41
            'cors' => [
42
                'Origin' => ['*'],
43
                'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
44
                'Access-Control-Request-Headers' => ['*'],
45
                'Access-Control-Allow-Credentials' => null,
46
                'Access-Control-Max-Age' => 86400,
47
                'Access-Control-Expose-Headers' => [
48
                    'X-Pagination-Current-Page',
49
                    'X-Pagination-Page-Count',
50
                    'X-Pagination-Per-Page',
51
                    'X-Pagination-Total-Count'
52
                ],
53
            ],
54
        ];
55
        $behaviors['authenticator'] = $auth;
56
        $behaviors['authenticator']['except'] = ['options'];
57
        return $behaviors;
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function actions()
64
    {
65
        return [
66
            'options' => [
67
                'class' => 'yii\rest\OptionsAction',
68
            ],
69
        ];
70
    }
71
}
72