mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Update naming to mutate
This commit is contained in:
parent
143756800f
commit
fd6cdf61c7
@ -324,13 +324,13 @@ echo Arithmetic::addCumulative(3); // outputs 3
|
||||
echo Arithmetic::addCumulative(3); // outputs 6
|
||||
```
|
||||
|
||||
### `@psalm-private-set`
|
||||
### `@psalm-private-mutate`
|
||||
|
||||
Used to annotate properties which can only be set in a private context. With this, public properties can be read from another class but only be modified within a method of its own class.
|
||||
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.
|
||||
|
||||
```php
|
||||
class Counter {
|
||||
/** @psalm-private-set */
|
||||
/** @psalm-private-mutate */
|
||||
public int $count = 0;
|
||||
|
||||
public function increment() : void {
|
||||
@ -340,9 +340,9 @@ class Counter {
|
||||
|
||||
$counter = new Counter();
|
||||
echo $counter->count; // outputs 0
|
||||
$counter->increment(); // Method can modify property
|
||||
$counter->increment(); // Method can mutate property
|
||||
echo $counter->count; // outputs 1
|
||||
$counter->count = 5; // This will fail as it's modifying a property directly
|
||||
$counter->count = 5; // This will fail as it's mutating a property directly
|
||||
```
|
||||
|
||||
## Type Syntax
|
||||
|
Loading…
Reference in New Issue
Block a user