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

Allow using enums as a token type #77

Merged
merged 1 commit into from
Dec 9, 2022
Merged

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Nov 28, 2022

Enums allow to avoid having to come up with values to assign for each name (unless you use a backed enum), and will provide more type safety.

There is a small performance impact:

PHPBench (1.2.7) running benchmarks... #standwithukraine
with configuration file: /home/greg/dev/doctrine-lexer/phpbench.json
with PHP version 8.1.12, xdebug ❌, opcache ❌
comparing [actual vs. original]

\Doctrine\Lexer\Benchmark\LexerBench

    benchLexer..............................I0 - [Mo10.680μs vs. Mo10.611μs] +0.65% (±0.00%)

Subjects: 1, Assertions: 0, Failures: 0, Errors: 0
+------------+------------+-----+--------+-----+---------------+-----------------+--------------+
| benchmark  | subject    | set | revs   | its | mem_peak      | mode            | rstdev       |
+------------+------------+-----+--------+-----+---------------+-----------------+--------------+
| LexerBench | benchLexer |     | 100000 | 1   | 1.723mb 0.00% | 10.680μs +0.65% | ±0.00% 0.00% |
+------------+------------+-----+--------+-----+---------------+-----------------+--------------+

Comment on lines 289 to 288
if ($token instanceof UnitEnum) {
$className = get_class($token);
} else {
$className = static::class;
}
Copy link
Member

@derrabus derrabus Nov 28, 2022

Choose a reason for hiding this comment

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

Suggested change
if ($token instanceof UnitEnum) {
$className = get_class($token);
} else {
$className = static::class;
}
if ($token instanceof UnitEnum) {
return $token::class . '::' . $token->name;
}
$className = static::class;

Copy link
Member Author

@greg0ire greg0ire Dec 9, 2022

Choose a reason for hiding this comment

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

Dynamic class names are not allowed in compile-time ::class fetch

This is about return $token::class . '::' . $token->name;, I will revert to using get_class.

@greg0ire
Copy link
Member Author

Pausing this as I discovered a BC-break that affects ORM and possibly more… I think I have to make the switch from array to Token opt-in somehow.

@greg0ire greg0ire modified the milestones: 1.3.0, 2.0.0 Nov 28, 2022
@greg0ire greg0ire marked this pull request as draft November 28, 2022 21:24
@greg0ire greg0ire changed the base branch from 1.3.x to 2.0.x December 9, 2022 12:54
Enums allow to avoid having to come up with values to assign for each
name (unless you use a backed enum), and will provide more type safety.
@greg0ire greg0ire marked this pull request as ready for review December 9, 2022 13:06
@greg0ire greg0ire requested a review from derrabus December 9, 2022 13:06
@greg0ire greg0ire merged commit d617a49 into doctrine:2.0.x Dec 9, 2022
@greg0ire greg0ire deleted the allow-enums branch December 9, 2022 15:24
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.

2 participants