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

Delete   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 14 2
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