Passed
Pull Request — master (#17)
by Alexander
08:51
created

OptionsRequestBehavior   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 17
ccs 0
cts 13
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A events() 0 6 1
A check() 0 7 2
1
<?php
2
3
namespace Horat1us\Yii\Behaviors;
4
5
use yii\base\Behavior;
6
use yii\base\ExitException;
7
use yii\web\Controller;
8
9
/**
10
 * Class OptionsRequestBehavior
11
 * @package Horat1us\Yii\Behaviors
12
 */
13
class OptionsRequestBehavior extends Behavior
14
{
15
    public function events()
16
    {
17
        return [
18
            Controller::EVENT_BEFORE_ACTION => 'check',
19
        ];
20
    }
21
22
    public function check(): void
23
    {
24
        if (\Yii::$app->request->method === 'OPTIONS') {
25
            \Yii::$app->response->send();
26
            throw new ExitException();
27
        }
28
    }
29
}
30