From c21e9917fa05ba4d97da464725471f53ab4fe0d8 Mon Sep 17 00:00:00 2001 From: Brown Date: Mon, 10 Jun 2019 14:41:21 -0400 Subject: [PATCH] Add config flag to prevent inferring property types from constructor --- src/Psalm/Config.php | 10 ++++++++++ src/Psalm/Internal/Visitor/ReflectorVisitor.php | 1 + 2 files changed, 11 insertions(+) diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index add21f4fe..367084658 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -264,6 +264,11 @@ class Config */ public $ignored_exceptions_and_descendants_in_global_scope = []; + /** + * @var bool + */ + public $infer_property_types_from_constructor = true; + /** * @var array */ @@ -725,6 +730,11 @@ class Config $config->parse_sql = $attribute_text === 'true' || $attribute_text === '1'; } + if (isset($config_xml['inferPropertyTypesFromConstructor'])) { + $attribute_text = (string) $config_xml['inferPropertyTypesFromConstructor']; + $config->infer_property_types_from_constructor = $attribute_text === 'true' || $attribute_text === '1'; + } + if (isset($config_xml->projectFiles)) { $config->project_files = ProjectFileFilter::loadFromXMLElement($config_xml->projectFiles, $base_dir, true); } diff --git a/src/Psalm/Internal/Visitor/ReflectorVisitor.php b/src/Psalm/Internal/Visitor/ReflectorVisitor.php index 8c6dd7a6a..65c77f5b6 100644 --- a/src/Psalm/Internal/Visitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/Visitor/ReflectorVisitor.php @@ -1818,6 +1818,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse && $stmt->stmts && $storage->params && $class_storage + && $this->config->infer_property_types_from_constructor ) { $assigned_properties = [];