Completed
Push — master ( 09c84d...fe53c9 )
by Dmitry
02:55
created

BaseCommand::loadFromRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
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
abstract class BaseCommand extends \yii\base\Model
14
{
15
    protected $entityClass;
16
17
    public function __construct($entityClass, $config = [])
18
    {
19
        $this->entityClass = $entityClass;
20
21
        parent::__construct($config);
22
    }
23
24
    public function loadFromRequest($request)
25
    {
26
        $this->load($this->getRequestData($request), '');
27
        $this->validate();
28
29
        return $this->hasErrors() ? $this->getErrors() : null;
30
    }
31
32
    public function getRequestData($request)
33
    {
34
        $get = $request->get();
35
        $post = $request->post();
36
37
        return array_merge($get, $post);
38
    }
39
40
    public function getEntityClass()
41
    {
42
        return $this->entityClass;
43
    }
44
}
45