-
Notifications
You must be signed in to change notification settings - Fork 128
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
[2.x] Indention Issues With Closures #206
Comments
possibly related to this issue squizlabs/PHP_CodeSniffer#1580 |
Here is a case that is failing from the CMS The sniff that is at issue is Joomla.ControlStructures.ControlStructuresBrackets.SpaceBeforeBrace expected // Sort the array by value of subarray
usort(
$languages,
function($a, $b) use ($that)
{
$ordering = $that->getState('list.ordering');
if (strtolower($that->getState('list.direction')) === 'asc')
{
return StringHelper::strcmp($a->$ordering, $b->$ordering);
}
else
{
return StringHelper::strcmp($b->$ordering, $a->$ordering);
}
}
); Current result of the sniff // Sort the array by value of subarray
usort(
$languages,
function($a, $b) use ($that)
{
$ordering = $that->getState('list.ordering');
if (strtolower($that->getState('list.direction')) === 'asc')
{
return StringHelper::strcmp($a->$ordering, $b->$ordering);
}
else
{
return StringHelper::strcmp($b->$ordering, $a->$ordering);
}
}
); |
Another CMS case from plugins\system\sef\sef.php where Joomla.ControlStructures.ControlStructuresBrackets.SpaceBeforeBrace fails on closures expected $buffer = preg_replace_callback(
$regex,
function ($match) use ($base, $protocols)
{
preg_match_all('#(?:[^\s]+)\s*(?:[\d\.]+[wx])?(?:\,\s*)?#i', $match[1], $matches);
foreach ($matches[0] as &$src)
{
$src = preg_replace('#^(?!/|' . $protocols . '|\#|\')(.+)#', $base . '$1', $src);
}
return ' srcset="' . implode($matches[0]) . '"';
},
$buffer
); Current result from sniff $buffer = preg_replace_callback(
$regex,
function ($match) use ($base, $protocols)
{
preg_match_all('#(?:[^\s]+)\s*(?:[\d\.]+[wx])?(?:\,\s*)?#i', $match[1], $matches);
foreach ($matches[0] as &$src)
{
$src = preg_replace('#^(?!/|' . $protocols . '|\#|\')(.+)#', $base . '$1', $src);
}
return ' srcset="' . implode($matches[0]) . '"';
},
$buffer
); |
I've done a little digging here. seems the issue might stem from our reliance on I propose we remove this portion of our rule and rely on the following parts of the ruleset that also cover this indenting Generic.WhiteSpace.ScopeIndent.IncorrectExact note: Generic.WhiteSpace.ScopeIndent reports in tabs as expected. I wonder what the overlap is and if we can eliminate some sniffs so there is no duplication in the checks. |
#218 now fixes this issue and has a test to verify that it fixes the issue. |
This might be covered by the same, but will this also cover PHP 7 anonymous classes, i.e. from com_code? |
Yes, I believe it should as I included |
Just did a test locally, seems to be good. I'll throw a test together. |
Close via #218 |
See https://travis-ci.org/joomla/jissues/jobs/273897032 for reference
Basically, indents for control structures aren't being handled correctly in Closures
The text was updated successfully, but these errors were encountered: