-
-
Notifications
You must be signed in to change notification settings - Fork 492
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
"No space after opening parenthesis is prohibited" when using traits #1071
Comments
Related to #764. @felixarntz Could you give me a more complete code sample ? The current one gives a syntax error so is not a valid test case. |
This is basically what the class looks like:
|
@felixarntz Ok, thanks. I've been able to reproduce the issue. For the short term, I'd suggest disabling that particular error message using: <!-- Disable it selectively for a few files: -->
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterOpenParenthesis">
<exclude-pattern>*/something*.php</exclude-pattern>
</rule>
<!-- Or disable it completely: -->
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterOpenParenthesis"/> For the longer term, I think we need to create a dedicated sniff for As input for the dedicated sniff - it should handle all cases, i.e.:
And let's not forget the variations within that with Refs: |
Ok, I've been gathering my thoughts around this sniff and there's quite some things to check for by the looks of it. So far I've come up with the following "rules": Generic:
Namespace use statements:
use My\Full\NSname;
use My\Full\Classname as Another;
use function My\Full\functionName as func;
use const My\Full\CONSTANT;
use My\Full\Classname as Another,
My\Full\NSname;
use some\namespace\{ ClassA, ClassB, ClassC as C };
use some\namespace\{
ClassA,
ClassB,
ClassC as C
}; Closure use statements:
function ( $quantity, $product ) use ( $tax, &$total ) {}; Trait use statements:
class MyHelloWorld {
use \Hello, World;
}
class MyHelloWorld {
use \Hello,
World;
}
class MyClass1 {
use \HelloWorld { sayHello as protected; }
}
class MyClass2 {
use HelloWorld {
sayHello as private myPrivateHello;
}
}
class SomeThing {
use Meta_Submodule_Trait, \Settings_Submodule_Trait {
Meta_Submodule_Trait::get_meta_fields as protected _get_meta_fields;
}
}
class Aliased_Talker {
use A, B {
B::smallTalk insteadof A;
A::bigTalk insteadof B;
B::bigTalk as talk;
}
}
class Foo {
use A, B, C {
C::bar insteadof A, B;
}
} @WordPress-Coding-Standards/wpcs-collaborators Opinions ? |
One more - for keyword which are not identified as such [*] and therefore don't trigger the [*] PHPCS changes the |
I like most of it, but I wonder if some of the subtle variants described in https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md (Draft) might be worth using? i.e. No spaces inside group use statements, traits on single line only, prescribed order of where each of these file-top items should go, etc.? |
Just been reading through it. Except for one of two things regarding spacing inside parenthesis and braces, it looks to be mostly in line with what I wrote above already. What I wrote down above is largely based on making things consistent with other WP rules regarding:
Regarding your suggestions (sorry for the lack of links, but the markdown of the fig doc does not allow for easy linking to sections - php-fig/fig-standards#911):
What do you mean by that ? I can't find that anywhere in the document. Or do you mean: no blank lines ? Or, alternatively, do you mean: no spaces inside the parenthesis for closure use statement ? In that case, that seems completely inconsistent with other parenthesis use in WP.
That seems counter-intuitive and inconsistent to me, especially when you look at the next example for importing traits and using
I like the "class use statement order" part - is that what you mean ? but am not sure if this would not go a bit too far for WP at this moment.
I also like the blank line directive:
This does seem like something which should be handled by a separate sniff though as the re-ordering of statements is quite complex. Maybe add this as a separate sniff with auto-fixer, but have everything be warnings, not errors ? And maybe not even add it to a ruleset, but make it opt-in (though it will ,of course, automatically be added to the For closures, I also like this part:
That's basically the same principle as outlined above for group use statements, but for multi-line closure opening declarations. |
I like the rules @jrfnl has outlined. In regard to what @GaryJones said:
use some\namespace\{ClassA, ClassB, ClassC as C}; No spaces inside the braces of the group use statements for namespaces does not feel right. In fact, it wouldn't feel right to me having a single-line group use statement at all. I'd probably always split it across multiple lines, because the braces feel like a control structure, and that is the rules for control structures. // I wouldn't do this:
use some\namespace\{ ClassA, ClassB, ClassC as C };
// Because I wouldn't do this:
if ( $var ) { return false; } They are two different things of course, but it just feels inconsistent. Same thing here: // I wouldn't do this:
class MyClass1 {
use \HelloWorld { sayHello as protected; }
}
// I'd do this:
class MyClass1 {
use \HelloWorld {
sayHello as protected;
}
} |
I'm easily swayed by the counter offers, since PSR-12 is, at best, draft, and even if it did make it through to deprecated PSR-2, it would still require take-up across the PHP community for it to be worthwhile.
I meant this bit:
I can't imagine that function-based and constant-based |
Found yet another one we need to check for: for group use namespace imports:
|
Noting here that the PSR12 standard inside PHP_CodeSniffer itself may start to handle some of this. |
The actual bug was fixed via #1926 which replaced the WPCS native utility functions with PHPCSUtils ones. The rules for traits and other |
I'm using traits in my code, and obviously WordPress doesn't. :)
The sniffer rules give give me the following error:
No space after opening parenthesis is prohibited
This happens for every line with a
use
statement for a trait, where I need to resolve a method conflict. For example:(in the above example the error is always thrown for the first line)
This is valid PHP, but causes an issue, probably because the codesniffer hasn't yet considered such cases. Not sure whether I should just disable this, or whether the sniff could be adjusted.
The text was updated successfully, but these errors were encountered: