diff --git a/config.xsd b/config.xsd index f4302e200..a0a9db0e3 100644 --- a/config.xsd +++ b/config.xsd @@ -62,6 +62,7 @@ + diff --git a/docs/running_psalm/configuration.md b/docs/running_psalm/configuration.md index c642eb3f0..43f42c3bf 100644 --- a/docs/running_psalm/configuration.md +++ b/docs/running_psalm/configuration.md @@ -90,6 +90,15 @@ Whether or not to use types as defined in docblocks. Defaults to `true`. ``` If not using all docblock types, you can still use docblock property types. Defaults to `false` (though only relevant if `useDocblockTypes` is `false`). +#### docblockPropertyTypesSealProperties + +```xml + +``` +Whether using @property in class docblocks should imply @psalm-seal-properties. Defaults to `true`. + #### usePhpDocMethodsWithoutMagicCall ```xml diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index de71b0d1e..a740d853b 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -194,6 +194,13 @@ class Config */ public $use_docblock_property_types = false; + /** + * Whether using property annotations in docblocks should implicitly seal properties + * + * @var bool + */ + public $docblock_property_types_seal_properties = true; + /** * Whether or not to throw an exception on first error * @@ -1049,6 +1056,7 @@ class Config $booleanAttributes = [ 'useDocblockTypes' => 'use_docblock_types', 'useDocblockPropertyTypes' => 'use_docblock_property_types', + 'docblockPropertyTypesSealProperties' => 'docblock_property_types_seal_properties', 'throwExceptionOnError' => 'throw_exception', 'hideExternalErrors' => 'hide_external_errors', 'hideAllErrorsExceptPassedFiles' => 'hide_all_errors_except_passed_files', diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index e581bbdb9..7b6cd0f4a 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -568,7 +568,9 @@ class ClassLikeNodeScanner } } - $storage->sealed_properties = true; + if ($this->config->docblock_property_types_seal_properties) { + $storage->sealed_properties = true; + } } foreach ($docblock_info->methods as $method) {