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

PHPCBF bug: foreach no brace with ${$var['key']} #1321

Closed
GaryJones opened this issue Mar 3, 2018 · 3 comments
Closed

PHPCBF bug: foreach no brace with ${$var['key']} #1321

GaryJones opened this issue Mar 3, 2018 · 3 comments

Comments

@GaryJones
Copy link
Member

Original code:

foreach ( $item['postmeta'] as $meta )
	${$meta['key']} = $meta['value'];

After phpcbf with PHP 7.1.7, this results in:

foreach ( $item['postmeta'] as $meta ) {
	$meta['key']} = $meta['value'];

Instead of:

foreach ( $item['postmeta'] as $meta ) {
	${$meta['key']} = $meta['value'];
}

Report:

  938 | ERROR   | [x] Opening brace should be on the same line as the declaration (WordPress.WhiteSpace.ControlStructureSpacing.OpenBraceNotSameLine)
  938 | ERROR   | [x] Expected 1 space(s) after closing parenthesis; found "\n            $" (Squiz.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis)
  939 | ERROR   | [x] Newline required after opening brace (Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace)
  939 | ERROR   | [x] Array keys must NOT be surrounded by spaces if they only contain a string or an integer. (WordPress.Arrays.ArrayKeySpacingRestrictions.SpacesAroundArrayKeys)
  939 | ERROR   | [x] Array keys must NOT be surrounded by spaces if they only contain a string or an integer. (WordPress.Arrays.ArrayKeySpacingRestrictions.SpacesAroundArrayKeys)
@jrfnl
Copy link
Member

jrfnl commented Mar 3, 2018

This looks to me like a known upstream issue with the Generic.ControlStructures.InlineControlStructure sniff which is getting confused over the curly braces of the variable variable.

See: squizlabs/PHP_CodeSniffer#1882

@jrfnl
Copy link
Member

jrfnl commented Mar 20, 2018

FYI: a fix has just been committed upstream which should take care of this. The fix will be included in the 3.3.0 release. If you would happen to have the chance to test it, that'd be great!

@jrfnl
Copy link
Member

jrfnl commented Jun 9, 2018

@GaryJones Can this issue be closed ? The issue was with PHPCS itself & has been fixed upstream.

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