mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #184 - prevent classes without reflected classes from breaking everything
This commit is contained in:
parent
a2a86ef9b1
commit
32ff386b4a
@ -447,8 +447,18 @@ class MethodChecker extends FunctionLikeChecker
|
||||
$declaring_method_id = self::getDeclaringMethodId($method_id);
|
||||
$appearing_method_id = self::getAppearingMethodId($method_id);
|
||||
|
||||
list($declaring_method_class) = explode('::', (string)$declaring_method_id);
|
||||
list($appearing_method_class) = explode('::', (string)$appearing_method_id);
|
||||
if ($declaring_method_id === null && $appearing_method_id === null) {
|
||||
list($method_class, $method_name) = explode('::', $method_id);
|
||||
|
||||
if ($method_name === '__construct') {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new \UnexpectedValueException('$declaring_method_id not expected to be null here');
|
||||
}
|
||||
|
||||
list($declaring_method_class) = explode('::', $declaring_method_id);
|
||||
list($appearing_method_class) = explode('::', $appearing_method_id);
|
||||
|
||||
// if the calling class is the same, we know the method exists, so it must be visible
|
||||
if ($appearing_method_class === $calling_context) {
|
||||
|
@ -12,13 +12,17 @@ class MethodCallTest extends TestCase
|
||||
public function providerFileCheckerValidCodeParse()
|
||||
{
|
||||
return [
|
||||
'notInCallMapTest' => [
|
||||
'<?php
|
||||
new DOMImplementation();'
|
||||
],
|
||||
'parentStaticCall' => [
|
||||
'<?php
|
||||
class A {
|
||||
/** @return void */
|
||||
public static function foo(){}
|
||||
}
|
||||
|
||||
|
||||
class B extends A {
|
||||
/** @return void */
|
||||
public static function bar(){
|
||||
@ -31,7 +35,7 @@ class MethodCallTest extends TestCase
|
||||
class Foo {
|
||||
public static function barBar() : void {}
|
||||
}
|
||||
|
||||
|
||||
(new Foo())->barBar();',
|
||||
],
|
||||
'staticInvocation' => [
|
||||
@ -39,11 +43,11 @@ class MethodCallTest extends TestCase
|
||||
class A {
|
||||
public static function fooFoo() : void {}
|
||||
}
|
||||
|
||||
|
||||
class B extends A {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
B::fooFoo();',
|
||||
],
|
||||
];
|
||||
@ -60,7 +64,7 @@ class MethodCallTest extends TestCase
|
||||
class Foo {
|
||||
public function barBar() : void {}
|
||||
}
|
||||
|
||||
|
||||
Foo::barBar();',
|
||||
'error_message' => 'InvalidStaticInvocation',
|
||||
],
|
||||
@ -70,7 +74,7 @@ class MethodCallTest extends TestCase
|
||||
/** @return void */
|
||||
public function foo(){}
|
||||
}
|
||||
|
||||
|
||||
class B extends A {
|
||||
/** @return void */
|
||||
public static function bar(){
|
||||
@ -84,10 +88,10 @@ class MethodCallTest extends TestCase
|
||||
class Foo {
|
||||
public static function barBar() : void {}
|
||||
}
|
||||
|
||||
|
||||
/** @var mixed */
|
||||
$a = (new Foo());
|
||||
|
||||
|
||||
$a->barBar();',
|
||||
'error_message' => 'MixedMethodCall',
|
||||
'error_levels' => [
|
||||
@ -99,7 +103,7 @@ class MethodCallTest extends TestCase
|
||||
'<?php
|
||||
class A {
|
||||
public function fooFoo() : void {}
|
||||
|
||||
|
||||
public function barBar() : void {
|
||||
self::fooFoo();
|
||||
}
|
||||
@ -119,7 +123,7 @@ class MethodCallTest extends TestCase
|
||||
'<?php
|
||||
class NullableClass {
|
||||
}
|
||||
|
||||
|
||||
class NullableBug {
|
||||
/**
|
||||
* @param string $className
|
||||
@ -129,7 +133,7 @@ class MethodCallTest extends TestCase
|
||||
if (!$className) { return null; }
|
||||
return new $className();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return NullableClass
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user