Issues (6)

controllers/QueryController.php (2 issues)

1
<?php
2
namespace tonisormisson\addressform\controllers;
3
4
use tonisormisson\addressform\AddressHelper;
5
use yii\web\Controller;
6
use Rinvex\Country\Country;
7
8
/**
9
 * Class QueryController
10
 * @package tonisormisson\addressform
11
 * @author Tõnis Ormisson <[email protected]>
12
 */
13
class QueryController extends Controller
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function init()
19
    {
20
        parent::init();
21
        \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
22
    }
23
24
25
    /**
26
     * @return array
27
     */
28
    public function actionRegions()
29
    {
30
        $request = \Yii::$app->request;
0 ignored issues
show
Documentation Bug introduced by
It seems like Yii::app->request can also be of type yii\web\Request. However, the property $request is declared as type yii\console\Request. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
31
        if ($request->isAjax && $request->post('depdrop_parents')) {
32
            $ids = $request->post('depdrop_parents');
33
            $countryCode = empty($ids[0]) ? null : $ids[0];
34
            $country = country($countryCode);
35
            if ($country instanceof Country) {
0 ignored issues
show
$country is always a sub-type of Rinvex\Country\Country.
Loading history...
36
                return ['output'=> (new AddressHelper())->formatList($country->getDivisions()), 'selected'=>'yee'];
37
            }
38
        }
39
        return ['output'=>'', 'selected'=>''];
40
    }
41
42
43
}
44