VKCOM/kphpstorm

Add a `null safety` check for instances when calling functions (`instances null problems`)

Opened this issue · 0 comments

KPHPStorm already has a check for primitives. We need to expand it and add a check for instances of the class.
Sample code:

<?php

declare(strict_types = 1);

function primitive_types() {
  /** @var int|null $type */
  $type = null;

  primitive_fun($type); // error: Can't pass '?int' to 'int' $var

  function primitive_fun(int $var) {
  }
}

function instances_types() {
  class Cls {
  }

  /** @var Cls|null $type */
  $type = null;

  instances_fun($type); // no error or warning

  function instances_fun(Cls $var) {
  }
}

Current check for primitives in KphpParameterTypeMismatchInspection