From 059d1ef177f082211e5f9d2630c4dc8c949f4505 Mon Sep 17 00:00:00 2001 From: Barney Laurance Date: Sat, 11 May 2019 14:58:53 +0100 Subject: [PATCH] psalm-internal - prevent static call to psalm-internal class from other namespace --- .../Expression/Call/StaticCallAnalyzer.php | 18 ++++ tests/PsalmInternalAnnotationTest.php | 102 +++++++++--------- 2 files changed, 69 insertions(+), 51 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php index 30d39b047..e147b2c16 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php @@ -579,6 +579,24 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\ } } + if($class_storage->psalmInternal){ + xdebug_break(); + } + if ($class_storage->psalmInternal + && $context->self + && strpos($context->self, trim($class_storage->psalmInternal, '\\') . '\\') !== 0 + ) { + if (IssueBuffer::accepts( + new InternalClass( + $fq_class_name . ' is marked internal to ' . $class_storage->psalmInternal, + new CodeLocation($statements_analyzer->getSource(), $stmt) + ), + $statements_analyzer->getSuppressedIssues() + )) { + // fall through + } + } + if ($class_storage->internal && $context->self && !$context->collect_initializations diff --git a/tests/PsalmInternalAnnotationTest.php b/tests/PsalmInternalAnnotationTest.php index 6460774c8..1fad47fc0 100644 --- a/tests/PsalmInternalAnnotationTest.php +++ b/tests/PsalmInternalAnnotationTest.php @@ -16,44 +16,44 @@ class PsalmInternalAnnotationTest extends TestCase return [ // 'internalMethodWithCall' => [ // ' [ -// ' [ + ' [ // ' [ // ' 'InternalMethod', // ], -// 'internalClassWithStaticCall' => [ -// ' 'InternalClass', -// ], + 'internalClassWithStaticCall' => [ + ' 'InternalClass', + ], // 'internalClassWithNew' => [ // '