TonisOrmisson /
yii2-address-form
| 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
|
|||
| 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
|
|||
| 36 | return ['output'=> (new AddressHelper())->formatList($country->getDivisions()), 'selected'=>'yee']; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | return ['output'=>'', 'selected'=>'']; |
||
| 40 | } |
||
| 41 | |||
| 42 | |||
| 43 | } |
||
| 44 |
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
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. 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.