1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Adjusted for actual implementation

This commit is contained in:
Matthew Brown 2020-02-02 15:38:41 -05:00
parent fd6cdf61c7
commit 93c613b5a3

View File

@ -324,13 +324,16 @@ echo Arithmetic::addCumulative(3); // outputs 3
echo Arithmetic::addCumulative(3); // outputs 6
```
### `@psalm-private-mutate`
### `@psalm-allow-private-mutation`
Used to annotate properties which can only be mutated in a private context. With this, public properties can be read from another class but only be mutated within a method of its own class.
Used to annotate readonly properties that can be mutated in a private context. With this, public properties can be read from another class but only be mutated within a method of its own class.
```php
class Counter {
/** @psalm-private-mutate */
/**
* @readonly
* @psalm-allow-private-mutation
*/
public int $count = 0;
public function increment() : void {
@ -342,7 +345,7 @@ $counter = new Counter();
echo $counter->count; // outputs 0
$counter->increment(); // Method can mutate property
echo $counter->count; // outputs 1
$counter->count = 5; // This will fail as it's mutating a property directly
$counter->count = 5; // This will fail, as it's mutating a property directly
```
## Type Syntax