Completed
Push — master ( 2dddc8...1df482 )
by Andrii
02:57
created

Command::getRequestData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * HiAPI Yii2 base project for building API
4
 *
5
 * @link      https://github.com/hiqdev/hiapi
6
 * @package   hiapi
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiapi\commands;
12
13
use Yii;
14
15
class Command extends \yii\base\Model
16
{
17
    protected static $handler;
18
19
    public static function getHandler()
20
    {
21
        if (!is_object(static::$handler)) {
22
            static::$handler = Yii::createObject(static::$handler);
23
        }
24
25
        return static::$handler;
26
    }
27
28
    public function loadFromRequest($request)
29
    {
30
        $this->load($this->getRequestData($request), '');
31
        $this->validate();
32
33
        return $this->hasErrors() ? $this->getErrors() : null;
34
    }
35
36
    public function getRequestData($request)
37
    {
38
        $get = $request->get();
39
        $post = $request->post();
40
41
        return array_merge($get, $post);
42
    }
43
}
44