Completed
Pull Request — master (#6)
by Angel
11:38
created

RestoreResource::actions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1.0019

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
ccs 7
cts 8
cp 0.875
crap 1.0019
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 2
    protected function verbs()
33
    {
34 2
        $verbs = parent::verbs();
35 2
        unset($verbs['create']);
36
37 2
        return $verbs;
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43 2
    public function actions()
44
    {
45 2
        $actions = parent::actions();
46 2
        unset($actions['create']);
47
        $actions['update'] = [
48 2
            'class' => Restore::class,
49 2
            'modelClass' => $this->modelClass,
50 2
            'findModel' => [$this, 'findModel'],
51
        ];
52
53 2
        return $actions;
54
    }
55
}
56