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

Update FunctionComment sniff with phpcs 2 fixes #159

Merged
merged 5 commits into from
Feb 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions Joomla/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,24 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
$var = '';
$varSpace = 0;
$comment = '';
$commentEnd = 0;

if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING)
{
$matches = array();
preg_match('/([^$&]+)(?:((?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches);
preg_match('/([^$&.]+)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches);

$typeLen = strlen($matches[1]);
$type = trim($matches[1]);
$typeSpace = ($typeLen - strlen($type));
$typeLen = strlen($type);

if ($typeLen > $maxType)
if (empty($matches) === false)
{
$maxType = $typeLen;
$typeLen = strlen($matches[1]);
$type = trim($matches[1]);
$typeSpace = ($typeLen - strlen($type));
$typeLen = strlen($type);

if ($typeLen > $maxType)
{
$maxType = $typeLen;
}
}

if (isset($matches[2]) === true)
Expand Down Expand Up @@ -231,7 +235,8 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
{
if ($tokens[$i]['code'] === T_DOC_COMMENT_STRING)
{
$comment .= ' ' . $tokens[$i]['content'];
$comment .= ' ' . $tokens[$i]['content'];
$commentEnd = $i;
}
}
}
Expand All @@ -258,6 +263,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
'type' => $type,
'var' => $var,
'comment' => $comment,
'comment_end' => $commentEnd,
'type_space' => $typeSpace,
'var_space' => $varSpace,
'align_space' => $tokens[($tag + 1)]['content']
Expand All @@ -268,6 +274,18 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
$foundParams = array();
$previousParam = null;

/*
* We want to use ... for all variable length arguments,
* so added this prefix to the variable name so comparisons are easier.
*/
foreach ($realParams as $pos => $param)
{
if ($param['variable_length'] === true)
{
$realParams[$pos]['name'] = '...' . $realParams[$pos]['name'];
}
}

foreach ($params as $pos => $param)
{
if ($param['var'] === '')
Expand Down