Completed
Push — master ( 6db6da...5370d9 )
by Angel
03:42
created

Delete::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace roaresearch\yii2\roa\actions;
4
5
use Yii;
6
use yii\web\ServerErrorHttpException;
7
8
/**
9
 * Deletes a record from the database.
10
 *
11
 * @author Angel (Faryshta) Guevara <[email protected]>
12
 */
13
class Delete extends Action
14
{
15
    /**
16
     * Applies the `delete()` method to a record.
17
     *
18
     * @param mixed $id the identifier value.
19
     */
20
    public function run($id)
21
    {
22
        $this->checkAccess(
23
            ($model = $this->findModel($id)),
24
            Yii::$app->request->getQueryParams()
25
        );
26
27
        if (false === $model->delete()) {
28
            throw new ServerErrorHttpException(
29
                'Failed to delete the object for unknown reason.'
30
            );
31
        }
32
        Yii::$app->getResponse()->setStatusCode(204);
33
    }
34
}
35