-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add rule to import classes except for built-in PHP classes. #9429
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
Add rule to import classes except for built-in PHP classes. #9429
Conversation
contributing/code/standards.rst
Outdated
@@ -194,6 +194,9 @@ Structure | |||
|
|||
* Do not use spaces around ``[`` offset accessor and before ``]`` offset accessor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this paragraph must now end with a semicolon
contributing/code/standards.rst
Outdated
@@ -194,6 +194,9 @@ Structure | |||
|
|||
* Do not use spaces around ``[`` offset accessor and before ``]`` offset accessor. | |||
|
|||
* Import classes from other namespaces with the ``use`` statement, except for | |||
built-in PHP classes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would reword this a bit:
* Add a ``use`` statement for every class that is not part of the global namespace.
Prefix class names from the global namespace with a single backslash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your proposal is more correct ... but I think @umulmrum's proposal is easier to understand: "builtin PHP classes" is more clear to me than "class names from the global namespace". But this is just my opinion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question beyond wording is, do we speak of built-in classes or of classes in the global namespace? Should user-land classes in the global namespace be imported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are user-land classes in the global namespace that we use, we also do not add a use
statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm 👍 for @xabbuh's proposal, it's more correct and people reading this CS guidelines are expert enough to know what the global namespace is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a simplified version of @xabbuh's proposal? "Add a use statement for every class that is not part of the global namespace."
Prefixing a class from the global namespace with a backslash is syntactically required when in a namespaced class, so this doesn't need to be written in a style guide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like @umulmrum's suggestion.
Thanks a lot for having improved this ... and congrats on your first contribution to this repository! |
…s. (umulmrum) This PR was squashed before being merged into the 2.7 branch (closes #9429). Discussion ---------- Add rule to import classes except for built-in PHP classes. Fixes #9426 (class imports were shown in the example but there was no rule in the text). Commits ------- 9c75279 Add rule to import classes except for built-in PHP classes.
Fixes #9426 (class imports were shown in the example but there was no rule in the text).