Skip to content

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

Closed

Conversation

umulmrum
Copy link
Contributor

Fixes #9426 (class imports were shown in the example but there was no rule in the text).

@@ -194,6 +194,9 @@ Structure

* Do not use spaces around ``[`` offset accessor and before ``]`` offset accessor.
Copy link
Member

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

@@ -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.
Copy link
Member

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.

Copy link
Member

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!

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@javiereguiluz
Copy link
Member

Thanks a lot for having improved this ... and congrats on your first contribution to this repository!

javiereguiluz added a commit that referenced this pull request Mar 16, 2018
…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.
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