-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Summary
Right now, model fields with a decimal type cast are annotated with the string type. This is correct, however typing them with a numeric-string type would help static analysis tools to better understand the code, and also to not flag valid code as incorrect. An example would be the following code:
/**
* @property-read string $value
*/
readonly class ModelWithString {
public function __construct(
public string $value,
) {}
}
/**
* @property-read numeric-string $value
*/
readonly class ModelWithNumericString {
public function __construct(
public string $value,
) {}
}
$a = new ModelWithString('1.23');
$result = $a->value + 3;
$b = new ModelWithNumericString('1.23');
$result2 = $b->value + 3;In the above snippet, PHPStan flags the addition operation using the ModelWithString value property as invalid, but is able to check that the operation using the ModelWithNumericString value property is valid code (link to PHPStan's playground).
I am willing to work on this.