Completed
Push — master ( 3c8880...e2c218 )
by Dmitry
06:42 queued 02:46
created

XEditableAction::loadCollection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 10
ccs 0
cts 9
cp 0
crap 6
rs 9.4285
1
<?php
2
3
/*
4
 * HiPanel core package
5
 *
6
 * @link      https://hipanel.com/
7
 * @package   hipanel-core
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\actions;
13
14
use hipanel\helpers\ArrayHelper;
15
use Yii;
16
17
/**
18
 * Class XEditableAction.
19
 */
20
class XEditableAction extends Action
21
{
22
    public function loadCollection($data = null)
23
    {
24
        if (is_null($data)) {
25
            $data = \Yii::$app->request->post();
26
        }
27
        return parent::loadCollection([[
28
            'id'          => ArrayHelper::remove($data, 'pk'),
29
            $data['name'] => ArrayHelper::remove($data, 'value', []),
30
        ]]);
31
    }
32
33
    public function run()
34
    {
35
        $error = $this->perform();
36
        if ($error) {
37
            Yii::$app->response->statusCode = 400;
38
        }
39
        return $error;
40
    }
41
}
42