From e878eeb6d0b08347d6cf4a1b403893b46a9ecaef Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 12 Jan 2021 11:25:27 +0100 Subject: [PATCH] Optionally allow trait static calls and property access --- config.xsd | 2 ++ src/Psalm/Config.php | 11 +++++++++++ .../Statements/Expression/Call/StaticCallAnalyzer.php | 2 +- .../Expression/Fetch/StaticPropertyFetchAnalyzer.php | 3 ++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/config.xsd b/config.xsd index 8d0d93ebb..88c93f539 100644 --- a/config.xsd +++ b/config.xsd @@ -37,6 +37,8 @@ + + diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 88c232c9e..0dffe8852 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -474,6 +474,15 @@ class Config */ public $allow_named_arg_calls = true; + /** + * @var bool + */ + public $allow_trait_static_call = false; + /** + * @var bool + */ + public $allow_trait_static_property_access = false; + /** @var array */ private $predefined_constants = []; @@ -754,6 +763,8 @@ class Config 'reportInfo' => 'report_info', 'restrictReturnTypes' => 'restrict_return_types', 'limitMethodComplexity' => 'limit_method_complexity', + 'allowTraitStaticCall' => 'allow_trait_static_call', + 'allowTraitStaticPropertyAccess' => 'allow_trait_static_property_access', ]; foreach ($booleanAttributes as $xmlName => $internalName) { diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php index 42db9703b..3fb51087c 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php @@ -148,7 +148,7 @@ class StaticCallAnalyzer extends CallAnalyzer : null, $statements_analyzer->getSuppressedIssues(), false, - false, + $codebase->config->allow_trait_static_call, false ); } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php index b7faa4447..a834c54c6 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php @@ -91,7 +91,8 @@ class StaticPropertyFetchAnalyzer $context->self, $context->calling_method_id, $statements_analyzer->getSuppressedIssues(), - false + false, + $codebase->config->allow_trait_static_property_access ) !== true) { return false; }