Skip to content

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

Description

@Danil42Russia

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions