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

PSR2.Methods.FunctionCallSignature strips some comments during fixing #1347

Merged
merged 1 commit into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function processSingleLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr

// Checking this: $value = my_function(...[*]).
$spaceBeforeClose = 0;
$prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($closer - 1), $openBracket, true);
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($closer - 1), $openBracket, true);
if ($tokens[$prev]['code'] === T_END_HEREDOC || $tokens[$prev]['code'] === T_END_NOWDOC) {
// Need a newline after these tokens, so ignore this rule.
return;
Expand All @@ -266,10 +266,31 @@ public function processSingleLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr
if ($spaceBeforeClose === 0) {
$phpcsFile->fixer->addContentBefore($closer, $padding);
} else {
$phpcsFile->fixer->replaceToken(($closer - 1), $padding);
}
}
}
$phpcsFile->fixer->beginChangeset();
$prev = ($closer - 1);

// We want to jump over any whitespace or inline comment and move the `)` after any other token.
while (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$prev]['code']]) === true) {
if (($tokens[$prev]['code'] === T_COMMENT)
&& (strpos($tokens[$prev]['content'], '*/') !== false)
) {
break;
}

$prev--;
}

$phpcsFile->fixer->addContent($prev, $padding.')');

$prevNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, ($closer - 1), null, true);
for ($i = ($prevNonWhitespace + 1); $i <= $closer; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}

$phpcsFile->fixer->endChangeset();
}//end if
}//end if
}//end if

}//end processSingleLineCall()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,29 @@ $qux = array_filter(
$this->listeners[] = $events->getSharedManager()->attach(
'Zend\Mvc\Application', MvcEvent::EVENT_DISPATCH, [$this, 'selectLayout'], 100
);

// @codingStandardsChangeSetting PSR2.Methods.FunctionCallSignature requiredSpacesBeforeClose 1
foo('Testing
multiline text'
);

foo('Testing
multiline text: ' // . $text
);

foo('Testing
multiline text: ' /* . $text */
);

foo('Testing
multiline text: ' /* . $text */
// . $other_text
);

foo('Testing
multiline text: ' /*
. $text
// . $text2
*/
);
// @codingStandardsChangeSetting PSR2.Methods.FunctionCallSignature requiredSpacesBeforeClose 0
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,26 @@ $this->listeners[] = $events->getSharedManager()->attach(
[$this, 'selectLayout'],
100
);

// @codingStandardsChangeSetting PSR2.Methods.FunctionCallSignature requiredSpacesBeforeClose 1
foo('Testing
multiline text' );

foo('Testing
multiline text: ' ) // . $text
;

foo('Testing
multiline text: ' /* . $text */ );

foo('Testing
multiline text: ' /* . $text */ )
// . $other_text
;

foo('Testing
multiline text: ' /*
. $text
// . $text2
*/ );
// @codingStandardsChangeSetting PSR2.Methods.FunctionCallSignature requiredSpacesBeforeClose 0
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public function getErrorList()
103 => 1,
111 => 1,
117 => 4,
121 => 1,
125 => 1,
129 => 1,
133 => 1,
138 => 1,
);

}//end getErrorList()
Expand Down