RestoreResource::verbs()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
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\Restore;
6
7
/**
8
 * Resource to handle restoration of soft deleted records.
9
 *
10
 * ```php
11
 * class ShopRestoreResource extends RestoreRestource
12
 * {
13
 *     public function baseQuery(): ActiveQuery
14
 *     {
15
 *         returns Shop::find()->andWhere(['isDeleted' => false]);
16
 *     }
17
 * }
18
 * ```
19
 *
20
 * The verb GET works on both collections and records to give reading access.
21
 *
22
 * By default the verb DELETE is enabled and its meant to permanently delete
23
 * a record but can be disabled by unsetting the verb.
24
 *
25
 * The verbs POST, PATCH and PUT work only on records to restore them.
26
 */
27
class RestoreResource extends Resource
28
{
29
    /**
30
     * @inheritdoc
31
     */
32 1
    protected function verbs()
33
    {
34 1
        $verbs = parent::verbs();
35 1
        unset($verbs['create']);
36
37 1
        return $verbs;
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43 1
    public function actions()
44
    {
45 1
        $actions = parent::actions();
46 1
        unset($actions['create']);
47 1
        $actions['update'] = [
48
            'class' => Restore::class,
49 1
            'modelClass' => $this->modelClass,
50
            'findModel' => [$this, 'findModel'],
51
        ];
52
53 1
        return $actions;
54
    }
55
}
56