Completed
Push — master ( 193c3c...281dde )
by Nate
07:20
created

Save::runInternal()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
nc 3
cc 3
eloc 7
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\ember\actions\element\traits;
10
11
use Craft;
12
use craft\base\ElementInterface;
13
use flipbox\ember\actions\traits\Populate;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 *
19
 * @method ElementInterface populate(ElementInterface $object);
20
 */
21
trait Save
22
{
23
    use Populate, Manage;
24
25
    /**
26
     * @inheritdoc
27
     * @param ElementInterface $element
28
     */
29
    public function runInternal(ElementInterface $element)
30
    {
31
        // Check access
32
        if (($access = $this->checkAccess($element)) !== true) {
33
            return $access;
34
        }
35
36
        if (!$this->performAction(
37
            $this->populate($element)
38
        )) {
39
            return $this->handleFailResponse($element);
40
        }
41
42
        return $this->handleSuccessResponse($element);
43
    }
44
45
    /**
46
     * @inheritdoc
47
     * @param ElementInterface $element
48
     */
49
    protected function performAction(ElementInterface $element): bool
50
    {
51
        return Craft::$app->getElements()->saveElement($element);
52
    }
53
}
54