From 255afe3f7ee310f62a8e5789b44c64f200653126 Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Sun, 19 Feb 2017 12:13:47 -0700 Subject: [PATCH 1/5] FunctionComment sniffs now support variadic functions Fix from https://github.com/squizlabs/PHP_CodeSniffer/commit/4966b545db497e038b3ba01fd21c0899be9365a9#diff-e366d95cd64d7200d6b59eca1b5e3093 Fix for https://github.com/squizlabs/PHP_CodeSniffer/issues/841 --- Joomla/Sniffs/Commenting/FunctionCommentSniff.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Joomla/Sniffs/Commenting/FunctionCommentSniff.php b/Joomla/Sniffs/Commenting/FunctionCommentSniff.php index 93381466..a5888625 100644 --- a/Joomla/Sniffs/Commenting/FunctionCommentSniff.php +++ b/Joomla/Sniffs/Commenting/FunctionCommentSniff.php @@ -190,7 +190,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co 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]); @@ -268,6 +268,16 @@ 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'] === '') From 92f7366e8d6c8325a6b79e1a8ef5eab13fac1dec Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Sun, 19 Feb 2017 12:18:09 -0700 Subject: [PATCH 2/5] FunctionComment sniffs now throw errors for some invalid @param line formats Fix for https://github.com/squizlabs/PHP_CodeSniffer/issues/1091 fix from https://github.com/squizlabs/PHP_CodeSniffer/commit/58dddd177fbc12e6a87301c77830625bb5d85b79 --- .../Commenting/FunctionCommentSniff.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Joomla/Sniffs/Commenting/FunctionCommentSniff.php b/Joomla/Sniffs/Commenting/FunctionCommentSniff.php index a5888625..2eff1e4f 100644 --- a/Joomla/Sniffs/Commenting/FunctionCommentSniff.php +++ b/Joomla/Sniffs/Commenting/FunctionCommentSniff.php @@ -192,14 +192,17 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co $matches = array(); 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) { + $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) @@ -272,8 +275,10 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co * 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) { + foreach ($realParams as $pos => $param) + { + if ($param['variable_length'] === true) + { $realParams[$pos]['name'] = '...'.$realParams[$pos]['name']; } } From b9f444d2e92d66e75cd66176ec1a12cb91852dff Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Sun, 19 Feb 2017 18:48:06 -0700 Subject: [PATCH 3/5] [CS] fix codestyle items --- Joomla/Sniffs/Commenting/FunctionCommentSniff.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Joomla/Sniffs/Commenting/FunctionCommentSniff.php b/Joomla/Sniffs/Commenting/FunctionCommentSniff.php index 2eff1e4f..ee6e2441 100644 --- a/Joomla/Sniffs/Commenting/FunctionCommentSniff.php +++ b/Joomla/Sniffs/Commenting/FunctionCommentSniff.php @@ -201,7 +201,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co if ($typeLen > $maxType) { - $maxType = $typeLen; + $maxType = $typeLen; } } @@ -272,14 +272,14 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co $previousParam = null; /* - * We want to use ... for all variable length arguments, + * 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']; + $realParams[$pos]['name'] = '...' . $realParams[$pos]['name']; } } From 52423cdb6eb25255e4cfdb852553b2ea1c6b99f7 Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Sat, 25 Feb 2017 10:08:25 -0700 Subject: [PATCH 4/5] partially add squizlabs/PHP_CodeSniffer@7e92909 changes --- Joomla/Sniffs/Commenting/FunctionCommentSniff.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Joomla/Sniffs/Commenting/FunctionCommentSniff.php b/Joomla/Sniffs/Commenting/FunctionCommentSniff.php index ee6e2441..a2152eb6 100644 --- a/Joomla/Sniffs/Commenting/FunctionCommentSniff.php +++ b/Joomla/Sniffs/Commenting/FunctionCommentSniff.php @@ -186,6 +186,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co $var = ''; $varSpace = 0; $comment = ''; + $commentEnd = 0; if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) { @@ -234,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; } } } @@ -261,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'] From c5f74a022710a6496802b0f0624949d3bf44ba0b Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Tue, 28 Feb 2017 10:04:35 -0700 Subject: [PATCH 5/5] Fix CS indenting --- Joomla/Sniffs/Commenting/FunctionCommentSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Joomla/Sniffs/Commenting/FunctionCommentSniff.php b/Joomla/Sniffs/Commenting/FunctionCommentSniff.php index a2152eb6..66a39ad1 100644 --- a/Joomla/Sniffs/Commenting/FunctionCommentSniff.php +++ b/Joomla/Sniffs/Commenting/FunctionCommentSniff.php @@ -186,7 +186,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co $var = ''; $varSpace = 0; $comment = ''; - $commentEnd = 0; + $commentEnd = 0; if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) { @@ -236,7 +236,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co if ($tokens[$i]['code'] === T_DOC_COMMENT_STRING) { $comment .= ' ' . $tokens[$i]['content']; - $commentEnd = $i; + $commentEnd = $i; } } }