-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DateTimeSubMethodThrowTypeExtension #3378
Conversation
a6e7fdd
to
37868e0
Compare
37868e0
to
229b9ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also: what about add
method?
return null; | ||
} | ||
|
||
return new ObjectType('DateMalformedStringException'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check the constant strings in the argument type and only throw this exception if some of them are invalid. Or if there are zero constant strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DateTime::sub
does not accepts constant strings, the signature is
public DateTime::sub(DateInterval $interval): DateTime
It only throw an exception if the DateInterval is relative like
$dt->sub(new DateInterval('next weekday'))
but I didnt see a way to have something like getDateIntervalConstantStrings()
. I wasn't sure
- if it would require to introduce a DateIntervalType like the QueryType (https://github.com/phpstan/phpstan-doctrine/blob/38db3bad8f1567d7bf64806738d724261f8a2b5c/src/Type/Doctrine/Query/QueryType.php#L11)
- if I was able to reproduce the implementation...
So as a first step, it improve the situation for all the PHP version lower than 8.3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also: what about add method?
public DateTime::add(DateInterval $interval): DateTime
does not throw exceptions.
return null; | ||
} | ||
|
||
return new ObjectType('DateMalformedStringException'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DateTime::sub
does not accepts constant strings, the signature is
public DateTime::sub(DateInterval $interval): DateTime
It only throw an exception if the DateInterval is relative like
$dt->sub(new DateInterval('next weekday'))
but I didnt see a way to have something like getDateIntervalConstantStrings()
. I wasn't sure
- if it would require to introduce a DateIntervalType like the QueryType (https://github.com/phpstan/phpstan-doctrine/blob/38db3bad8f1567d7bf64806738d724261f8a2b5c/src/Type/Doctrine/Query/QueryType.php#L11)
- if I was able to reproduce the implementation...
So as a first step, it improve the situation for all the PHP version lower than 8.3.
I apologize, I didn't check the method signature before. But I don't see the same behaviour you do. Can you show me when the |
I made a copy-paste error, it should have been a
It seems like the DateInterval constructor does not accept relative interval. So
won't throw an exception while
could. |
Thank you. |
Closes phpstan/phpstan#11503