final class Uuid
{
private string $value;
public function __construct(string $value)
{
if (static::isValid($value)) {
$this->value = 'foo';
return;
}
throw new InvalidArgumentException('Provided UUid is invalid');
}
public static function isValid(string $value): bool
{
return preg_match('/whatever/', $value) === 1;
}
}
Psalm reports:
ERROR: PropertyNotSetInConstructor - 7:20 - Property Uuid::$value is not defined in constructor of Uuid and in any private or final methods called in the constructor
I believe this is a false positive, as the constructor can only return when the value has been set.
https://psalm.dev/r/7a6e02239a
```php
value = 'foo';
return;
}
throw new InvalidArgumentException('Provided UUid is invalid');
}
public static function isValid(string $value): bool
{
return preg_match('/whatever/', $value) === 1;
}
}
```
```
Psalm output (using commit d19088b):
ERROR: PropertyNotSetInConstructor - 5:20 - Property Uuid::$value is not defined in constructor of Uuid and in any private or final methods called in the constructor
```
Consider the following code:
Psalm reports:
I believe this is a false positive, as the constructor can only return when the value has been set.
Reproduce: https://psalm.dev/r/7a6e02239a