mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 13:51:54 +01:00
Merge pull request #7434 from zoonru/disable_var_parsing
Add configuration option to disable @var parsing everywhere except for properties.
This commit is contained in:
commit
f72f2f6fbe
@ -109,6 +109,7 @@
|
|||||||
</xs:documentation>
|
</xs:documentation>
|
||||||
</xs:annotation>
|
</xs:annotation>
|
||||||
</xs:attribute>
|
</xs:attribute>
|
||||||
|
<xs:attribute name="disableVarParsing" type="xs:boolean" default="false" />
|
||||||
<xs:attribute name="errorLevel" type="xs:integer" default="2" />
|
<xs:attribute name="errorLevel" type="xs:integer" default="2" />
|
||||||
<xs:attribute name="reportMixedIssues" type="xs:boolean" default="true" />
|
<xs:attribute name="reportMixedIssues" type="xs:boolean" default="true" />
|
||||||
<xs:attribute name="useDocblockTypes" type="xs:boolean" default="true" />
|
<xs:attribute name="useDocblockTypes" type="xs:boolean" default="true" />
|
||||||
|
@ -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`.
|
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
|
||||||
|
<psalm
|
||||||
|
disableVarParsing="[bool]"
|
||||||
|
/>
|
||||||
|
```
|
||||||
|
|
||||||
|
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
|
#### strictBinaryOperands
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
|
@ -373,6 +373,11 @@ class Config
|
|||||||
*/
|
*/
|
||||||
public $add_param_default_to_docblock_type = false;
|
public $add_param_default_to_docblock_type = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $disable_var_parsing = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
@ -920,6 +925,7 @@ class Config
|
|||||||
'allowFileIncludes' => 'allow_includes',
|
'allowFileIncludes' => 'allow_includes',
|
||||||
'strictBinaryOperands' => 'strict_binary_operands',
|
'strictBinaryOperands' => 'strict_binary_operands',
|
||||||
'rememberPropertyAssignmentsAfterCall' => 'remember_property_assignments_after_call',
|
'rememberPropertyAssignmentsAfterCall' => 'remember_property_assignments_after_call',
|
||||||
|
'disableVarParsing' => 'disable_var_parsing',
|
||||||
'allowPhpStormGenerics' => 'allow_phpstorm_generics',
|
'allowPhpStormGenerics' => 'allow_phpstorm_generics',
|
||||||
'allowStringToStandInForClass' => 'allow_string_standin_for_class',
|
'allowStringToStandInForClass' => 'allow_string_standin_for_class',
|
||||||
'disableSuppressAll' => 'disable_suppress_all',
|
'disableSuppressAll' => 'disable_suppress_all',
|
||||||
|
@ -155,13 +155,15 @@ class AssignmentAnalyzer
|
|||||||
$template_type_map = $statements_analyzer->getTemplateTypeMap();
|
$template_type_map = $statements_analyzer->getTemplateTypeMap();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$var_comments = CommentAnalyzer::getTypeFromComment(
|
$var_comments = $codebase->config->disable_var_parsing
|
||||||
$doc_comment,
|
? []
|
||||||
$statements_analyzer->getSource(),
|
: CommentAnalyzer::getTypeFromComment(
|
||||||
$statements_analyzer->getAliases(),
|
$doc_comment,
|
||||||
$template_type_map,
|
$statements_analyzer->getSource(),
|
||||||
$file_storage->type_aliases
|
$statements_analyzer->getAliases(),
|
||||||
);
|
$template_type_map,
|
||||||
|
$file_storage->type_aliases
|
||||||
|
);
|
||||||
} catch (IncorrectDocblockException $e) {
|
} catch (IncorrectDocblockException $e) {
|
||||||
IssueBuffer::maybeAdd(
|
IssueBuffer::maybeAdd(
|
||||||
new MissingDocblockType(
|
new MissingDocblockType(
|
||||||
|
@ -74,14 +74,16 @@ class ReturnAnalyzer
|
|||||||
$file_storage = $file_storage_provider->get($statements_analyzer->getFilePath());
|
$file_storage = $file_storage_provider->get($statements_analyzer->getFilePath());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$var_comments = CommentAnalyzer::arrayToDocblocks(
|
$var_comments = $codebase->config->disable_var_parsing
|
||||||
$doc_comment,
|
? []
|
||||||
$parsed_docblock,
|
: CommentAnalyzer::arrayToDocblocks(
|
||||||
$statements_analyzer->getSource(),
|
$doc_comment,
|
||||||
$statements_analyzer->getAliases(),
|
$parsed_docblock,
|
||||||
$statements_analyzer->getTemplateTypeMap(),
|
$statements_analyzer->getSource(),
|
||||||
$file_storage->type_aliases
|
$statements_analyzer->getAliases(),
|
||||||
);
|
$statements_analyzer->getTemplateTypeMap(),
|
||||||
|
$file_storage->type_aliases
|
||||||
|
);
|
||||||
} catch (DocblockParseException $e) {
|
} catch (DocblockParseException $e) {
|
||||||
IssueBuffer::maybeAdd(
|
IssueBuffer::maybeAdd(
|
||||||
new InvalidDocblock(
|
new InvalidDocblock(
|
||||||
|
@ -57,13 +57,15 @@ class StaticAnalyzer
|
|||||||
$var_comments = [];
|
$var_comments = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$var_comments = CommentAnalyzer::arrayToDocblocks(
|
$var_comments = $codebase->config->disable_var_parsing
|
||||||
$doc_comment,
|
? []
|
||||||
$parsed_docblock,
|
: CommentAnalyzer::arrayToDocblocks(
|
||||||
$statements_analyzer->getSource(),
|
$doc_comment,
|
||||||
$statements_analyzer->getSource()->getAliases(),
|
$parsed_docblock,
|
||||||
$statements_analyzer->getSource()->getTemplateTypeMap()
|
$statements_analyzer->getSource(),
|
||||||
);
|
$statements_analyzer->getSource()->getAliases(),
|
||||||
|
$statements_analyzer->getSource()->getTemplateTypeMap()
|
||||||
|
);
|
||||||
} catch (IncorrectDocblockException $e) {
|
} catch (IncorrectDocblockException $e) {
|
||||||
IssueBuffer::maybeAdd(
|
IssueBuffer::maybeAdd(
|
||||||
new MissingDocblockType(
|
new MissingDocblockType(
|
||||||
|
@ -442,14 +442,16 @@ class StatementsAnalyzer extends SourceAnalyzer
|
|||||||
$var_comments = [];
|
$var_comments = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$var_comments = CommentAnalyzer::arrayToDocblocks(
|
$var_comments = $codebase->config->disable_var_parsing
|
||||||
$docblock,
|
? []
|
||||||
$statements_analyzer->parsed_docblock,
|
: CommentAnalyzer::arrayToDocblocks(
|
||||||
$statements_analyzer->getSource(),
|
$docblock,
|
||||||
$statements_analyzer->getAliases(),
|
$statements_analyzer->parsed_docblock,
|
||||||
$template_type_map,
|
$statements_analyzer->getSource(),
|
||||||
$file_storage->type_aliases
|
$statements_analyzer->getAliases(),
|
||||||
);
|
$template_type_map,
|
||||||
|
$file_storage->type_aliases
|
||||||
|
);
|
||||||
} catch (IncorrectDocblockException $e) {
|
} catch (IncorrectDocblockException $e) {
|
||||||
IssueBuffer::maybeAdd(
|
IssueBuffer::maybeAdd(
|
||||||
new MissingDocblockType(
|
new MissingDocblockType(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user