BaseCommand::loadFromServerRequest()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 2
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
use Psr\Http\Message\ServerRequestInterface;
14
15
abstract class BaseCommand extends \yii\base\Model
16
{
17
    public function loadFromServerRequest(ServerRequestInterface $request): bool
18
    {
19
        $data = $request->getParsedBody() ?: $request->getQueryParams();
20
21
        return $this->load($data, '');
22
    }
23
24
    /**
25
     * XXX doubt it should be needed!
26
     */
27
    public function commandName(): string
28
    {
29
        return strtr((new \ReflectionObject($this))->getShortName(), [
30
            'Command' => '',
31
        ]);
32
    }
33
}
34