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

Enable using commands containing underscores #1365

Merged

Conversation

mlocati
Copy link
Contributor

@mlocati mlocati commented Oct 7, 2022

? !
Type improvement
BC Break yes
Fixed issues #1364

Summary

As explained in #1364, it's currently impossible to define commands containing underscores.

This PR enables it.

For example:

  • a FoobarCommand class defines the /foobar command
  • a FooBarCommand class defines the /foo_bar command (this is a BC break)

PS: closes #1364

@noplanman
Copy link
Member

Thanks @mlocati, sorry for the huge delay in replying to your PR.

@TiiFuchs and @jacklul, what do you think? I'm wondering if the BC break will be a problem 🤔

Copy link
Member

@TiiFuchs TiiFuchs left a comment

Choose a reason for hiding this comment

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

I added some comments with a few thoughts.
If @noplanman agrees, those should be changed before merging.

In regards of the BC-breaking change, I think that should be ok.
We could eventually write something into the log if there is a case, that has changed bevavior, so the user has a clue, if something is wrong all of the sudden.
I think that would be pretty smart. Log output should be removed in a later version though.

src/Telegram.php Outdated Show resolved Hide resolved
protected function classNameToCommandName(string $class): string
{
if (!preg_match('/^(.+)Command$/', $class, $matches)) {
return '';
Copy link
Member

Choose a reason for hiding this comment

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

Returning an empty string if no command is found, is not good style. Should return null instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Returning an empty string if no command is found, is not good style.

I usually agree, except the cases when an empty string is not a valid value (like this case).
To check if the return value is valid we'd need to check if it's not null OR is an empty string: by avoiding null we simply have to check for empty strings.

src/Telegram.php Outdated Show resolved Hide resolved
@TiiFuchs TiiFuchs merged commit f79c799 into php-telegram-bot:develop Nov 7, 2022
@mlocati mlocati deleted the enable-commands-with-underscore branch November 7, 2022 12:05
@noplanman
Copy link
Member

Thanks @mlocati 🎉 😃

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.

Unable to define commands containing underscore
3 participants