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

Generic.Whitespace.LanguageConstructSpacing should not be checking namespace operators #2194

Closed
jrfnl opened this issue Oct 19, 2018 · 5 comments
Milestone

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Oct 19, 2018

The Generic.Whitespace.LanguageConstructSpacing sniff demands one space after PHP language construct keywords.

The namespace keyword however, is both a construct as well as an operator, depending on the context.

<?php
// Here it is a language construct:
namespace MyProject;

// Here it is an operator or as the documentation states:
// "It is the namespace equivalent of the self operator for classes. "
namespace\func(); // calls function MyProject\func()
$a = new namespace\sub\cname(); // instantiates object of class MyProject\sub\cname

See: http://php.net/manual/en/language.namespaces.nsconstants.php#example-256

Currently, the sniff will trigger errors for the use of the keyword as an operator and demand one space after the keyword.

This, to me, is unexpected.

Is this intended behaviour or a bug ? /cc @gmponos

@gsherwood
Copy link
Member

It's a bug

@jrfnl
Copy link
Contributor Author

jrfnl commented Oct 19, 2018

Ok, will fix it.

@gsherwood gsherwood added this to the 3.4.0 milestone Oct 19, 2018
@jrfnl
Copy link
Contributor Author

jrfnl commented Oct 19, 2018

@gsherwood Just checking - should just the bug be fixed, i.e. no error should be thrown, or should the sniff be enhanced to demand no space between the namespace keyword as an operator and the \ in that case ?

@gsherwood
Copy link
Member

I think it should just ignore the namespace keyword when used like that. Rules for how namespaces are defined (spaces or not, newlines or not, etc) should probably be left to other sniffs.

@jrfnl
Copy link
Contributor Author

jrfnl commented Oct 19, 2018

Okidoki. Though IIRC there is no sniff which currently covers the namespace keyword as an operator. I think I'll address this when I finally get round to fixing #2150.

@gsherwood gsherwood changed the title Generic/LanguageConstructSpacing: namespace operator bug or feature ? Generic.Whitespace.LanguageConstructSpacing should not be checking namespace operators Nov 2, 2018
gsherwood added a commit that referenced this issue Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants