Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@property annotations: allow *not* implying @psalm-seal-properties #9568

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<xs:attribute name="reportMixedIssues" type="xs:boolean" default="true" />
<xs:attribute name="useDocblockTypes" type="xs:boolean" default="true" />
<xs:attribute name="useDocblockPropertyTypes" type="xs:boolean" default="false" />
<xs:attribute name="docblockPropertyTypesSealProperties" type="xs:boolean" default="true" />
<xs:attribute name="usePhpDocMethodsWithoutMagicCall" type="xs:boolean" default="false" />
<xs:attribute name="usePhpDocPropertiesWithoutMagicCall" type="xs:boolean" default="false" />
<xs:attribute name="skipChecksOnUnresolvableIncludes" type="xs:boolean" default="false" />
Expand Down
9 changes: 9 additions & 0 deletions docs/running_psalm/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<psalm
docblockPropertyTypesSealProperties="[bool]"
>
```
Whether using @property in class docblocks should imply @psalm-seal-properties. Defaults to `true`.

#### usePhpDocMethodsWithoutMagicCall

```xml
Expand Down
8 changes: 8 additions & 0 deletions src/Psalm/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -1049,6 +1056,7 @@ private static function fromXmlAndPaths(
$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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,9 @@ public function start(PhpParser\Node\Stmt\ClassLike $node): ?bool
}
}

$storage->sealed_properties = true;
if ($this->config->docblock_property_types_seal_properties) {
$storage->sealed_properties = true;
}
}

foreach ($docblock_info->methods as $method) {
Expand Down