RuleController::actionUpdateStatus()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
namespace app\modules\v1\controllers;
4
5
use app\core\exceptions\InvalidArgumentException;
6
use app\core\models\Rule;
7
use app\core\requests\RuleUpdateStatusRequest;
8
use app\core\traits\ServiceTrait;
9
use Yii;
10
use yii\db\Exception;
11
use yii\web\NotFoundHttpException;
12
13
/**
14
 * Rule controller for the `v1` module
15
 */
16
class RuleController extends ActiveController
17
{
18
    use ServiceTrait;
19
20
    public $modelClass = Rule::class;
21
    public $defaultOrder = ['sort' => SORT_ASC, 'id' => SORT_DESC];
22
    public $partialMatchAttributes = ['name'];
23
24
    /**
25
     * @param int $id
26
     * @return Rule
27
     * @throws Exception
28
     * @throws NotFoundHttpException
29
     */
30
    public function actionCopy(int $id): Rule
31
    {
32
        return $this->ruleService->copy($id);
33
    }
34
35
    /**
36
     * @param int $id
37
     * @return Rule
38
     * @throws Exception
39
     * @throws InvalidArgumentException
40
     * @throws NotFoundHttpException
41
     */
42
    public function actionUpdateStatus(int $id): Rule
43
    {
44
        $params = Yii::$app->request->bodyParams;
45
        $model = new RuleUpdateStatusRequest();
46
        /** @var RuleUpdateStatusRequest $model */
47
        $model = $this->validate($model, $params);
48
49
        return $this->ruleService->updateStatus($id, $model->status);
50
    }
51
}
52