-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
chore: Tokens::offsetSet
- explicit validation of input
#9004
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
Conversation
Tokens::offsetSet
- explicit validation of input
Utils::triggerDeprecation(new \InvalidArgumentException(\sprintf( | ||
'Tokens should be a list of Token instances - newval must be a Token. This will be enforced in version %d.0.', | ||
Application::getMajorVersion() + 1 | ||
))); |
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.
I guess it already fails when you try to use other values because of the registerFoundToken
call below. registerFoundToken
has a native Token
type hint.
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.
yeah, but crash is super ugly when coming from nested function and not part of visible contract for this method (and can change any moment when internals of method change)
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.
Yes, but not sure if a deprecation is necessary when it already fails anyway. IMO we could just add explicit failure here.
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.
tbh was wondering about same. not sure. especially as registerFoundToken
is called conditionally
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.
especially as registerFoundToken is called conditionally
Hmm yes. At first I thought the equals
condition would always fail for values other than Tokens. But actually it can succeed.
$tokens[$i] = new Token(';');
$tokens[$i] = ';'; // <-- no registerFoundToken call, so probably no failure
Ok so the deprecation might be better to be safe.
(but I guess you can't do anything useful with values other than Token instances)
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.
let me conclude as-is for now then. we can always revisit and promote to exception on v3 , if new reason comes in
inspired by #9001