BUGFIX: Keep line ending for inline comments
* As test showed, line ending was removed for inline comments "//". * This line ending is now kept. * Test does not fail anymore. Relates: #46, #3
This commit is contained in:
parent
a78d94ab13
commit
d7911cccee
7 changed files with 19 additions and 9 deletions
|
@ -234,7 +234,7 @@ abstract class AbstractClassnameChecker implements PhpCsSniff
|
||||||
|
|
||||||
$phpcsFile->fixer->replaceToken(
|
$phpcsFile->fixer->replaceToken(
|
||||||
$classnamePosition,
|
$classnamePosition,
|
||||||
$this->getTokenForReplacement($prefix . $this->getNewClassname($classname), $classname)
|
$this->getTokenForReplacement($prefix . $this->getNewClassname($classname), $classname, $phpcsFile)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,9 +244,10 @@ abstract class AbstractClassnameChecker implements PhpCsSniff
|
||||||
*
|
*
|
||||||
* @param string $newClassname
|
* @param string $newClassname
|
||||||
* @param string $originalClassname
|
* @param string $originalClassname
|
||||||
|
* @param PhpCsFile $phpcsFile
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getTokenForReplacement($newClassname, $originalClassname)
|
protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile)
|
||||||
{
|
{
|
||||||
return $newClassname;
|
return $newClassname;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,9 +79,10 @@ class Typo3Update_Sniffs_LegacyClassnames_DocCommentSniff extends AbstractClassn
|
||||||
*
|
*
|
||||||
* @param string $newClassname
|
* @param string $newClassname
|
||||||
* @param string $originalClassname
|
* @param string $originalClassname
|
||||||
|
* @param PhpCsFile $phpcsFile
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getTokenForReplacement($newClassname, $originalClassname)
|
protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile)
|
||||||
{
|
{
|
||||||
$token = explode(' ', $this->originalTokenContent);
|
$token = explode(' ', $this->originalTokenContent);
|
||||||
|
|
||||||
|
|
|
@ -83,13 +83,19 @@ class Typo3Update_Sniffs_LegacyClassnames_InlineCommentSniff extends AbstractCla
|
||||||
*
|
*
|
||||||
* @param string $newClassname
|
* @param string $newClassname
|
||||||
* @param string $originalClassname
|
* @param string $originalClassname
|
||||||
|
* @param PhpCsFile $phpcsFile
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getTokenForReplacement($newClassname, $originalClassname)
|
protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile)
|
||||||
{
|
{
|
||||||
$token = preg_split('/\s+/', $this->originalTokenContent);
|
$token = preg_split('/\s+/', $this->originalTokenContent);
|
||||||
$token[$this->getClassnamePosition($token)] = $newClassname;
|
$token[$this->getClassnamePosition($token)] = $newClassname;
|
||||||
|
|
||||||
|
// Keep line ending, removed by preg_split
|
||||||
|
if ($token[0] === '//') {
|
||||||
|
$token[count($token)] = $phpcsFile->eolChar;
|
||||||
|
}
|
||||||
|
|
||||||
return implode(' ', $token);
|
return implode(' ', $token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,9 +75,10 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithMakeInstanceSniff ext
|
||||||
*
|
*
|
||||||
* @param string $newClassname
|
* @param string $newClassname
|
||||||
* @param string $originalClassname
|
* @param string $originalClassname
|
||||||
|
* @param PhpCsFile $phpcsFile
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getTokenForReplacement($newClassname, $originalClassname)
|
protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile)
|
||||||
{
|
{
|
||||||
return $this->getTokenReplacementForString($newClassname);
|
return $this->getTokenReplacementForString($newClassname);
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,9 +85,10 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithObjectManagerSniff ex
|
||||||
*
|
*
|
||||||
* @param string $newClassname
|
* @param string $newClassname
|
||||||
* @param string $originalClassname
|
* @param string $originalClassname
|
||||||
|
* @param PhpCsFile $phpcsFile
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getTokenForReplacement($newClassname, $originalClassname)
|
protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile)
|
||||||
{
|
{
|
||||||
return $this->getTokenReplacementForString($newClassname);
|
return $this->getTokenReplacementForString($newClassname);
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,9 +74,10 @@ class Typo3Update_Sniffs_LegacyClassnames_IsACallSniff extends AbstractClassname
|
||||||
*
|
*
|
||||||
* @param string $newClassname
|
* @param string $newClassname
|
||||||
* @param string $originalClassname
|
* @param string $originalClassname
|
||||||
|
* @param PhpCsFile $phpcsFile
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getTokenForReplacement($newClassname, $originalClassname)
|
protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile)
|
||||||
{
|
{
|
||||||
return $this->getTokenReplacementForString($newClassname);
|
return $this->getTokenReplacementForString($newClassname);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
--- tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff/InputFileForIssues.php
|
--- tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff/InputFileForIssues.php
|
||||||
+++ PHP_CodeSniffer
|
+++ PHP_CodeSniffer
|
||||||
@@ -23,16 +23,14 @@
|
@@ -23,16 +23,16 @@
|
||||||
{
|
{
|
||||||
public function something()
|
public function something()
|
||||||
{
|
{
|
||||||
|
@ -21,4 +21,3 @@
|
||||||
$variable;
|
$variable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue