Passed
Push — master ( d9b33a...61038f )
by Alexander
05:52 queued 31s
created

OptionsRequestBehavior::events()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 2
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Horat1us\Yii\Behaviors;
4
5
use yii\base;
6
use yii\web;
7
use yii\di;
8
9
/**
10
 * Class OptionsRequestBehavior
11
 * @package Horat1us\Yii\Behaviors
12
 */
13
class OptionsRequestBehavior extends base\Behavior
14
{
15
    /** @var string|array|web\Request */
16
    public $request = 'request';
17
18
    /** @var string|array|web\Response */
19
    public $response = 'response';
20
21 2
    public function init(): void
22
    {
23 2
        parent::init();
24 2
        $this->request = di\Instance::ensure($this->request,  web\Request::class);
25 2
        $this->response = di\Instance::ensure($this->response,  web\Response::class);
26 2
    }
27
28
    public function events(): array
29
    {
30
        return [
31
            web\Controller::EVENT_BEFORE_ACTION => 'check',
32
        ];
33
    }
34
35 2
    public function check(): void
36
    {
37 2
        if ($this->request->method === 'OPTIONS') {
38 1
            $this->response->send();
39 1
            throw new base\ExitException();
40
        }
41 1
    }
42
}
43