Update::proct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace roaresearch\yii2\roa\actions;
4
5
use roaresearch\yii2\roa\hal\ARContract;
6
use Yii;
7
use yii\{base\Model, web\ServerErrorHttpException};
8
9
/**
10
 * Action to update the attributes in a record.
11
 * @author Angel (Faryshta) Guevara <[email protected]>
12
 */
13
class Update extends ProctRecordAction
14
{
15
    use LoadFileTrait;
16
17
    /**
18
     * @inheritdoc
19
     */
20
    protected string $errorMessage = 'Update failed for unknown reasons.';
21
22
    /**
23
     * @var string the scenario to be assigned to the model before it is
24
     * validated and updated.
25
     */
26
    public string $scenario = Model::SCENARIO_DEFAULT;
27
28
    /**
29
     * @inheritdoc
30
     */
31 2
    protected function proct(ARContract $model, array $params): bool
32
    {
33 2
        $model->setScenario($this->scenario);
34 2
        $model->load(
35 2
            Yii::$app->request->getBodyParams() + $this->parseFileAttributes(),
36
            ''
37
        );
38
39 2
        return false !== $model->save() || $model->hasErrors();
40
    }
41
}
42