Completed
Push — master ( 1df482...f40dd5 )
by Andrii
03:13
created

BaseCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 2
cbo 2
dl 0
loc 29
ccs 0
cts 19
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getHandler() 0 8 2
A loadFromRequest() 0 7 2
A getRequestData() 0 7 1
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
abstract class BaseCommand 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