Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add forward-compatible constants for Command return codes #38199

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

Closed
wants to merge 1 commit into from
Closed

Add forward-compatible constants for Command return codes #38199

wants to merge 1 commit into from

Conversation

arjenm
Copy link
Contributor

@arjenm arjenm commented Sep 15, 2020

Q A
Branch? 4.4
Bug fix? no
New feature? maybe
Deprecations? no
Tickets Adds forward compatibility for new constants from #35478
License MIT

In Symfony 5.0 it is mandatory to return an integer from Command::execute-methods.

In 5.1 two constants have been added to prevent having to write magic numbers or redefine constants for the two most used return codes.
This change includes those two constants in 4.4, to allow an easier transition to 5.1 compatible Commands.

I.e., now the constants can be used right away, rather than first changing all Commands to use magic numbers or custom constants and replacing those with these Symfony-constants after the upgrade to 5.1.

@chalasr
Copy link
Member

chalasr commented Sep 15, 2020

Extending the public API is considered a new feature.
Using hardcoded numbers is fine (Symfony will keep doing so internally), I don't think this is worth bypassing the rule.

@chalasr chalasr added this to the 4.4 milestone Sep 15, 2020
@wouterj
Copy link
Member

wouterj commented Sep 15, 2020

Tbh, return codes 0 = success and !0 = failure is something used across the complete shell/terminal industry. I don't think it'll ever change, so returning numbers is quite fine imho. It's mostly a DX feature (making it easier to understand for people not used to shell), so I don't think it's needed to step away from the normal feature-rules.

@arjenm
Copy link
Contributor Author

arjenm commented Sep 15, 2020

@wouterj Magic numbers are generally considered a bad practice, even (actually, especially) if they will stay the same forever.

If it is unnecessary, why add those constants to 5.1? And why bother clearly preferring them in the documentation:
https://symfony.com/doc/current/console.html

Sure, using regular ints works... but for anyone who prefers not using magic numbers, this is a cleaner fix.

In our case it requires 83 Commands that need to be adjusted twice, rather than just once. And yes, if we use custom constants in the first change, we can do a few find-replaces in the second change. But that is still work that can trivially be made unnecessary.

@fabpot
Copy link
Member

fabpot commented Sep 16, 2020

Closing as we do not add new features in old branches.

@fabpot fabpot closed this Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.