Skip to content

Conversation

keradus
Copy link
Member

@keradus keradus commented Aug 31, 2025

inspired by #9001

@keradus keradus changed the title chore: Tokens::offsetSet - explicit validation of input chore: Tokens::offsetSet - explicit validation of input Aug 31, 2025
@coveralls
Copy link

coveralls commented Aug 31, 2025

Coverage Status

coverage: 94.671% (-0.02%) from 94.693%
when pulling e89a028 on Tokens
into 8444566 on master.

@keradus keradus marked this pull request as ready for review August 31, 2025 22:41
@keradus keradus enabled auto-merge (squash) August 31, 2025 22:54
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
)));
Copy link
Member

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.

Copy link
Member Author

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)

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

@gharlan gharlan Sep 1, 2025

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)

Copy link
Member Author

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

@keradus keradus disabled auto-merge September 1, 2025 12:19
@keradus keradus merged commit cab8620 into master Sep 1, 2025
62 checks passed
@keradus keradus deleted the Tokens branch September 1, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants