Completed
Push — master ( cf704a...bfb117 )
by Dmitry
73:02 queued 58:03
created

BaseCommand::loadFromServerRequest()   A

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, '');
0 ignored issues
show
Bug introduced by
It seems like $data defined by $request->getParsedBody(...quest->getQueryParams() on line 19 can also be of type object; however, yii\base\Model::load() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
22
    }
23
}
24