Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

earlyTerminatingMethodCalls does not recognize methods from interfaces #2030

Closed
mpesari opened this issue Mar 25, 2019 · 1 comment
Closed

Comments

@mpesari
Copy link

mpesari commented Mar 25, 2019

Summary of a problem or a feature request

I have an interface with a method that terminates the script. PHPStan handles this differently from a class with a plain terminating method (the latter works just fine.)

Code snippet that reproduces the problem

phpstan.neon:

parameters:
  earlyTerminatingMethodCalls:
    InterfaceWithTerminatingMethod:
      - terminate
    AnotherClassWithTerminatingMethod:
      - terminate

autoload.php:

<?php

interface InterfaceWithTerminatingMethod {
  public static function terminate(): void;
}

class ClassImplementingTerminatingMethod implements InterfaceWithTerminatingMethod {
  public static function terminate(): void {
    exit;
  }
}

class AnotherClassWithTerminatingMethod {
  public static function terminate(): void {
    exit;
  }
}

test.php:

<?php

try {
  $hello = 'Do something that might throw';
  throw new Exception;
} catch (Exception $e) {
  // AnotherClassWithTerminatingMethod::terminate(); // this works
  ClassImplementingTerminatingMethod::terminate();
}

var_dump($hello); // error
$ phpstan analyse -l 7 -c phpstan.neon -a autoload.php test.php
 ------ --------------------------------------- 
  Line   test.php                               
 ------ --------------------------------------- 
  11     Variable $hello might not be defined.  
 ------ --------------------------------------- 

Expected output

I assume PHPStan should recognize early terminating methods even if they come from an interface.

@ondrejmirtes
Copy link
Member

Hi,
try latest dev-master if it helps: 24ce5a5

@lock lock bot locked as resolved and limited conversation to collaborators Dec 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants