diff --git a/config.xsd b/config.xsd
index 9805ba361..e2301ea78 100644
--- a/config.xsd
+++ b/config.xsd
@@ -109,6 +109,7 @@
+
diff --git a/docs/running_psalm/configuration.md b/docs/running_psalm/configuration.md
index f8735e390..8b1fdf5c5 100644
--- a/docs/running_psalm/configuration.md
+++ b/docs/running_psalm/configuration.md
@@ -116,6 +116,16 @@ The PHPDoc `@method` annotation normally only applies to classes with a `__call`
```
The PHPDoc `@property`, `@property-read` and `@property-write` annotations normally only apply to classes with `__get`/`__set` methods. Setting this to `true` allows you to use the `@property`, `@property-read` and `@property-write` annotations to override property existence checks and resulting property types. Defaults to `false`.
+#### disableVarParsing
+
+```xml
+
+```
+
+Disables parsing of `@var` PHPDocs everywhere except for properties. Setting this to `true` can remove many false positives due to outdated `@var` annotations, used before integrations of Psalm generics and proper typing, enforcing Single Source Of Truth principles. Defaults to `false`.
+
#### strictBinaryOperands
```xml
diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php
index ac4355b55..2ca59125d 100644
--- a/src/Psalm/Config.php
+++ b/src/Psalm/Config.php
@@ -373,6 +373,11 @@ class Config
*/
public $add_param_default_to_docblock_type = false;
+ /**
+ * @var bool
+ */
+ public $disable_var_parsing = false;
+
/**
* @var bool
*/
@@ -920,6 +925,7 @@ class Config
'allowFileIncludes' => 'allow_includes',
'strictBinaryOperands' => 'strict_binary_operands',
'rememberPropertyAssignmentsAfterCall' => 'remember_property_assignments_after_call',
+ 'disableVarParsing' => 'disable_var_parsing',
'allowPhpStormGenerics' => 'allow_phpstorm_generics',
'allowStringToStandInForClass' => 'allow_string_standin_for_class',
'disableSuppressAll' => 'disable_suppress_all',
diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php
index 50ccf068d..51e919192 100644
--- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php
+++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php
@@ -155,13 +155,15 @@ class AssignmentAnalyzer
$template_type_map = $statements_analyzer->getTemplateTypeMap();
try {
- $var_comments = CommentAnalyzer::getTypeFromComment(
- $doc_comment,
- $statements_analyzer->getSource(),
- $statements_analyzer->getAliases(),
- $template_type_map,
- $file_storage->type_aliases
- );
+ $var_comments = $codebase->config->disable_var_parsing
+ ? []
+ : CommentAnalyzer::getTypeFromComment(
+ $doc_comment,
+ $statements_analyzer->getSource(),
+ $statements_analyzer->getAliases(),
+ $template_type_map,
+ $file_storage->type_aliases
+ );
} catch (IncorrectDocblockException $e) {
IssueBuffer::maybeAdd(
new MissingDocblockType(
diff --git a/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php
index 6936fc33e..79832cc9d 100644
--- a/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php
+++ b/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php
@@ -74,14 +74,16 @@ class ReturnAnalyzer
$file_storage = $file_storage_provider->get($statements_analyzer->getFilePath());
try {
- $var_comments = CommentAnalyzer::arrayToDocblocks(
- $doc_comment,
- $parsed_docblock,
- $statements_analyzer->getSource(),
- $statements_analyzer->getAliases(),
- $statements_analyzer->getTemplateTypeMap(),
- $file_storage->type_aliases
- );
+ $var_comments = $codebase->config->disable_var_parsing
+ ? []
+ : CommentAnalyzer::arrayToDocblocks(
+ $doc_comment,
+ $parsed_docblock,
+ $statements_analyzer->getSource(),
+ $statements_analyzer->getAliases(),
+ $statements_analyzer->getTemplateTypeMap(),
+ $file_storage->type_aliases
+ );
} catch (DocblockParseException $e) {
IssueBuffer::maybeAdd(
new InvalidDocblock(
diff --git a/src/Psalm/Internal/Analyzer/Statements/StaticAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/StaticAnalyzer.php
index 6133afd45..12d068d52 100644
--- a/src/Psalm/Internal/Analyzer/Statements/StaticAnalyzer.php
+++ b/src/Psalm/Internal/Analyzer/Statements/StaticAnalyzer.php
@@ -57,13 +57,15 @@ class StaticAnalyzer
$var_comments = [];
try {
- $var_comments = CommentAnalyzer::arrayToDocblocks(
- $doc_comment,
- $parsed_docblock,
- $statements_analyzer->getSource(),
- $statements_analyzer->getSource()->getAliases(),
- $statements_analyzer->getSource()->getTemplateTypeMap()
- );
+ $var_comments = $codebase->config->disable_var_parsing
+ ? []
+ : CommentAnalyzer::arrayToDocblocks(
+ $doc_comment,
+ $parsed_docblock,
+ $statements_analyzer->getSource(),
+ $statements_analyzer->getSource()->getAliases(),
+ $statements_analyzer->getSource()->getTemplateTypeMap()
+ );
} catch (IncorrectDocblockException $e) {
IssueBuffer::maybeAdd(
new MissingDocblockType(
diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
index 10ea73806..78a25799a 100644
--- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
+++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
@@ -442,14 +442,16 @@ class StatementsAnalyzer extends SourceAnalyzer
$var_comments = [];
try {
- $var_comments = CommentAnalyzer::arrayToDocblocks(
- $docblock,
- $statements_analyzer->parsed_docblock,
- $statements_analyzer->getSource(),
- $statements_analyzer->getAliases(),
- $template_type_map,
- $file_storage->type_aliases
- );
+ $var_comments = $codebase->config->disable_var_parsing
+ ? []
+ : CommentAnalyzer::arrayToDocblocks(
+ $docblock,
+ $statements_analyzer->parsed_docblock,
+ $statements_analyzer->getSource(),
+ $statements_analyzer->getAliases(),
+ $template_type_map,
+ $file_storage->type_aliases
+ );
} catch (IncorrectDocblockException $e) {
IssueBuffer::maybeAdd(
new MissingDocblockType(