Bug report
https://www.php.net/manual/en/class.dateinterval.php#dateinterval.props.days documents that a DateInterval returned by DateTimeInterface::diff always have days set (as it can compute it in this case).
It would be great if phpstan could automatically refine the value in this case, to avoid having to add explicit assert($interval->days !== false) just after.
As DateInterval is a mutable object in PHP, this should be implemented using a refined type (that would be invalidated when passing that object to an impure function or when assigning a value to the property) rather than by changing the property type (i.e. exactly what happens when writing this assert explicitly).
Code snippet that reproduces the problem
https://phpstan.org/r/0e888080-29db-4ff8-8f03-58a7e726c2b1
Expected output
No error being reported.
Did PHPStan help you today? Did it make you happy in any way?
No response
Bug report
https://www.php.net/manual/en/class.dateinterval.php#dateinterval.props.days documents that a DateInterval returned by
DateTimeInterface::diffalways havedaysset (as it can compute it in this case).It would be great if phpstan could automatically refine the value in this case, to avoid having to add explicit
assert($interval->days !== false)just after.As DateInterval is a mutable object in PHP, this should be implemented using a refined type (that would be invalidated when passing that object to an impure function or when assigning a value to the property) rather than by changing the property type (i.e. exactly what happens when writing this assert explicitly).
Code snippet that reproduces the problem
https://phpstan.org/r/0e888080-29db-4ff8-8f03-58a7e726c2b1
Expected output
No error being reported.
Did PHPStan help you today? Did it make you happy in any way?
No response