Skip to content
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

Replace object-like array with class #83

Closed
wants to merge 1 commit into from

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Nov 29, 2022

Alternative to #79 (which I still prefer)

The new class is templatable, which should enable us to specify that the ORM Lexer is an Lexer<self::T_*>, and in the future, define an enum called TokenType in the ORM, and switch to Lexer<TokenType>.

I tested on the ORM, and with this solution, the PHPUnit test suite no longer breaks.

The static analysis is broken because of the impossibility to know if we have an array or an object, and because I want to reuse the Token name.

I've considered adding another template param to AbstractLexer to fix this, but then it would have to be removed in 2.0, which would make implementing compatibility with 2.0 challenging from the SA point of view.

The new class is templatable, which should enable us to specify that the
ORM Lexer is an Lexer<self::T_*>, and in the future, define an enum
called TokenType in the ORM, and switch to Lexer<TokenType>.
use function in_array;

/** @template T of string|int */
final class Token
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I'm reusing this name, I need to rename the type alias in AbstractLexer to ArrayToken, which should break static analysis.

@greg0ire greg0ire marked this pull request as ready for review November 29, 2022 21:34
@malarzm
Copy link
Member

malarzm commented Nov 29, 2022

The static analysis is broken because of the impossibility to know if we have an array or an object

Dang, I thought we'd be able to leverage https://psalm.dev/docs/annotating_code/type_syntax/conditional_types/ to know what we're dealing with, but I wrongly assumed we'd be able to check feature flag :/

@SenseException
Copy link
Member

I would expect the ArrayAccess usage of Token here without the deprecation messages. Wouldn't that at least keep some of the old code?

@greg0ire
Copy link
Member Author

greg0ire commented Dec 9, 2022

Closing in favor of the more sensible #79

@greg0ire greg0ire closed this Dec 9, 2022
@greg0ire greg0ire deleted the token-class-deux branch December 9, 2022 13:06
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