SaveRecordTrait::runInternal()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 11
cp 0
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-ember/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-ember/
7
 */
8
9
namespace flipbox\craft\ember\actions\records;
10
11
use flipbox\craft\ember\actions\PopulateTrait;
12
use yii\db\ActiveRecord;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 2.0.0
17
 *
18
 * @method ActiveRecord populate(ActiveRecord $record)
19
 */
20
trait SaveRecordTrait
21
{
22
    use PopulateTrait,
23
        ManageRecordTrait;
24
25
    /**
26
     * @inheritdoc
27
     * @param ActiveRecord $record
28
     */
29
    public function runInternal(ActiveRecord $record)
30
    {
31
        // Populate
32
        $this->populate($record);
33
34
        // Check access
35
        if (($access = $this->checkAccess($record)) !== true) {
36
            return $access;
37
        }
38
39
        if (!$this->performAction($record)) {
40
            return $this->handleFailResponse($record);
41
        }
42
43
        return $this->handleSuccessResponse($record);
44
    }
45
}
46