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:
Daniel Siepmann 2017-04-06 11:54:56 +02:00
parent a78d94ab13
commit d7911cccee
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
7 changed files with 19 additions and 9 deletions

View file

@ -234,7 +234,7 @@ abstract class AbstractClassnameChecker implements PhpCsSniff
$phpcsFile->fixer->replaceToken(
$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 $originalClassname
* @param PhpCsFile $phpcsFile
* @return string
*/
protected function getTokenForReplacement($newClassname, $originalClassname)
protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile)
{
return $newClassname;
}

View file

@ -79,9 +79,10 @@ class Typo3Update_Sniffs_LegacyClassnames_DocCommentSniff extends AbstractClassn
*
* @param string $newClassname
* @param string $originalClassname
* @param PhpCsFile $phpcsFile
* @return string
*/
protected function getTokenForReplacement($newClassname, $originalClassname)
protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile)
{
$token = explode(' ', $this->originalTokenContent);

View file

@ -83,13 +83,19 @@ class Typo3Update_Sniffs_LegacyClassnames_InlineCommentSniff extends AbstractCla
*
* @param string $newClassname
* @param string $originalClassname
* @param PhpCsFile $phpcsFile
* @return string
*/
protected function getTokenForReplacement($newClassname, $originalClassname)
protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile)
{
$token = preg_split('/\s+/', $this->originalTokenContent);
$token[$this->getClassnamePosition($token)] = $newClassname;
// Keep line ending, removed by preg_split
if ($token[0] === '//') {
$token[count($token)] = $phpcsFile->eolChar;
}
return implode(' ', $token);
}
}

View file

@ -75,9 +75,10 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithMakeInstanceSniff ext
*
* @param string $newClassname
* @param string $originalClassname
* @param PhpCsFile $phpcsFile
* @return string
*/
protected function getTokenForReplacement($newClassname, $originalClassname)
protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile)
{
return $this->getTokenReplacementForString($newClassname);
}

View file

@ -85,9 +85,10 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithObjectManagerSniff ex
*
* @param string $newClassname
* @param string $originalClassname
* @param PhpCsFile $phpcsFile
* @return string
*/
protected function getTokenForReplacement($newClassname, $originalClassname)
protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile)
{
return $this->getTokenReplacementForString($newClassname);
}

View file

@ -74,9 +74,10 @@ class Typo3Update_Sniffs_LegacyClassnames_IsACallSniff extends AbstractClassname
*
* @param string $newClassname
* @param string $originalClassname
* @param PhpCsFile $phpcsFile
* @return string
*/
protected function getTokenForReplacement($newClassname, $originalClassname)
protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile)
{
return $this->getTokenReplacementForString($newClassname);
}

View file

@ -1,6 +1,6 @@
--- tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff/InputFileForIssues.php
+++ PHP_CodeSniffer
@@ -23,16 +23,14 @@
@@ -23,16 +23,16 @@
{
public function something()
{
@ -21,4 +21,3 @@
$variable;
}
}