ProfileResource::behaviors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace roaresearch\yii2\roa\controllers;
4
5
use roaresearch\yii2\roa\actions\{
6
    ProfileFileStream,
7
    ProfileUpdate,
8
    ProfileView
9
};
10
use Yii;
11
use yii\{base\Model, filters\VerbFilter, rest\OptionsAction};
12
13
class ProfileResource extends \yii\rest\Controller
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public $updateScenario = Model::SCENARIO_DEFAULT;
19
20
    /**
21
     * @var string[] array used in `actions\Update::fileAttributes`
22
     * @see actions\LoadFileTrait::$fileAttributes
23
     */
24
    public $updateFileAttributes = [];
25
26
    /**
27
     * @inheritdoc
28
     */
29 4
    public function behaviors()
30
    {
31
        return [
32
            // content negotiator, autenticator, etc moved by default to
33
            // api container
34
            'verbFilter' => [
35
                'class' => VerbFilter::class,
36 4
                'actions' => $this->verbs(),
37
            ],
38
        ];
39
    }
40
41
    /**
42
     * @inheridoc
43
     */
44 4
    protected function verbs()
45
    {
46 4
        $verbs = ['GET', 'PUT', 'PATCH', 'OPTIONS'];
47
48
        return [
49 4
            'view' => $verbs,
50
            'update' => $verbs,
51
            'options' => $verbs,
52
        ];
53
    }
54
55
    /**
56
     * @inheridoc
57
     */
58 4
    public function actions()
59
    {
60
        return [
61
            'view' => ['class' => ProfileView::class],
62
            'update' => [
63
                'class' => ProfileUpdate::class,
64 4
                'scenario' => $this->updateScenario,
65 4
                'fileAttributes' => $this->updateFileAttributes,
66
            ],
67
            'options' => ['class' => OptionsAction::class],
68
            'file-stream' => ['class' => ProfileFileStream::class],
69
        ];
70
    }
71
}
72