Skip to content

Commit

Permalink
Merge pull request #7851 from jrmajor/docs/ignore-var
Browse files Browse the repository at this point in the history
Document `@psalm-ignore-variable-*`
  • Loading branch information
orklah committed Apr 9, 2022
2 parents ab1ae8f + ce25b39 commit eeb12bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 25 additions & 0 deletions docs/annotating_code/supported_annotations.md
Expand Up @@ -553,6 +553,31 @@ Incidentally, it will change the inferred type for the following code:
```
The type of `$a` is `array<array-key, int>` without `@no-named-arguments` but becomes `list<int>` with it, because it excludes the case where the offset would be a string with the name of the parameter

### `@psalm-ignore-variable-property` and `@psalm-ignore-variable-method`

Instructs Psalm to ignore variable property fetch / variable method call when looking for dead code.
```php
class Foo
{
// this property can be deleted by Psalter,
// as potential reference in get() is ignored
public string $bar = 'bar';

public function get(string $name): mixed
{
/** @psalm-ignore-variable-property */
return $this->{$name};
}
}
```
When Psalm encounters variable property, it treats all properties in given class as potentially referenced.
With `@psalm-ignore-variable-property` annotation, this reference is ignored.

While `PossiblyUnusedProperty` would be emitted in both cases, using `@psalm-ignore-variable-property`
would allow [Psalter](../manipulating_code/fixing.md) to delete `Foo::$bar`.

`@psalm-ignore-variable-method` behaves the same way, but for variable method calls.

### `@psalm-yield`

Used to specify the type of value which will be sent back to a generator when an annotated object instance is yielded.
Expand Down
2 changes: 0 additions & 2 deletions tests/DocumentationTest.php
Expand Up @@ -76,8 +76,6 @@ class DocumentationTest extends TestCase
'@psalm-assert-untainted',
'@psalm-flow',
'@psalm-generator-return',
'@psalm-ignore-variable-method',
'@psalm-ignore-variable-property',
'@psalm-override-method-visibility',
'@psalm-override-property-visibility',
'@psalm-scope-this',
Expand Down

0 comments on commit eeb12bc

Please sign in to comment.