Skip to content

Commit

Permalink
Add documentation and schema entry for inferPropertyTypesFromConstructor
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Jun 22, 2021
1 parent 6d4d166 commit f24f361
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<xs:attribute name="ignoreInternalFunctionFalseReturn" type="xs:boolean" default="true" />
<xs:attribute name="ignoreInternalFunctionNullReturn" type="xs:boolean" default="true" />
<xs:attribute name="includePhpVersionsInErrorBaseline" type="xs:boolean" default="false" />
<xs:attribute name="inferPropertyTypesFromConstructor" type="xs:boolean" default="true" />
<xs:attribute name="loadXdebugStub" type="xs:boolean">
<xs:annotation>
<xs:documentation xml:lang="en">
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 @@ -213,6 +213,15 @@ When `true`, Psalm ignores possibly-false issues stemming from return values of
```
When `true`, Psalm ignores possibly-null issues stemming from return values of internal array functions (like `current`) that may return null, but do so rarely. Defaults to `true`.

#### inferPropertyTypesFromConstructor

```xml
<psalm
inferPropertyTypesFromConstructor="[bool]"
>
```
When `true`, Psalm infers property types from assignments seen in straightforward constructors. Defaults to `true`.

#### findUnusedVariablesAndParams
```xml
<psalm
Expand Down
9 changes: 9 additions & 0 deletions tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,15 @@ public function testSetsUniversalObjectCrates()
$this->assertContains('datetime', $this->project_analyzer->getConfig()->getUniversalObjectCrates());
}

public function testInferPropertyTypesFromConstructorIsRead(): void
{
$cfg = Config::loadFromXML(
dirname(__DIR__, 2),
'<?xml version="1.0"?><psalm inferPropertyTypesFromConstructor="false"></psalm>'
);
$this->assertFalse($cfg->infer_property_types_from_constructor);
}

/**
* @return array<string, array{0: int, 1: int|null}>
*/
Expand Down

0 comments on commit f24f361

Please sign in to comment.