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

Save   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 33
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A runInternal() 0 15 3
A performAction() 0 4 1
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