Merge pull request #51 from DanielSiepmann/hotfix/48-multiple-type-hints

BUGFIX: Allow multiple type hints in php docs
This commit is contained in:
Daniel Hürtgen 2017-04-04 16:36:47 +02:00 committed by GitHub
commit 22c2f4cb1c
6 changed files with 36 additions and 21 deletions

View file

@ -234,7 +234,7 @@ abstract class AbstractClassnameChecker implements PhpCsSniff
$phpcsFile->fixer->replaceToken( $phpcsFile->fixer->replaceToken(
$classnamePosition, $classnamePosition,
$this->getTokenForReplacement($prefix . $this->getNewClassname($classname)) $this->getTokenForReplacement($prefix . $this->getNewClassname($classname), $classname)
); );
} }
@ -242,12 +242,13 @@ abstract class AbstractClassnameChecker implements PhpCsSniff
* String to use for replacing / fixing the token. * String to use for replacing / fixing the token.
* Default is class name itself, can be overwritten in sniff for special behaviour. * Default is class name itself, can be overwritten in sniff for special behaviour.
* *
* @param string $classname * @param string $newClassname
* @param string $originalClassname
* @return string * @return string
*/ */
protected function getTokenForReplacement($classname) protected function getTokenForReplacement($newClassname, $originalClassname)
{ {
return $classname; return $newClassname;
} }
/** /**

View file

@ -66,22 +66,32 @@ class Typo3Update_Sniffs_LegacyClassnames_DocCommentSniff extends AbstractClassn
if ($classnamePosition === false) { if ($classnamePosition === false) {
return; return;
} }
$classname = explode(' ', $tokens[$classnamePosition]['content'])[0]; $classnames = explode('|', explode(' ', $tokens[$classnamePosition]['content'])[0]);
$this->originalTokenContent = $tokens[$classnamePosition]['content']; $this->originalTokenContent = $tokens[$classnamePosition]['content'];
foreach ($classnames as $classname) {
$this->addFixableError($phpcsFile, $classnamePosition, $classname); $this->addFixableError($phpcsFile, $classnamePosition, $classname);
} }
}
/** /**
* As token contains more then just class name, we have to build new content ourself. * As token contains more then just class name, we have to build new content ourself.
* *
* @param string $classname * @param string $newClassname
* @param string $originalClassname
* @return string * @return string
*/ */
protected function getTokenForReplacement($classname) protected function getTokenForReplacement($newClassname, $originalClassname)
{ {
$token = explode(' ', $this->originalTokenContent); $token = explode(' ', $this->originalTokenContent);
$token[0] = $classname;
$classNames = explode('|', $token[0]);
foreach ($classNames as $position => $classname) {
if ($classname === $originalClassname) {
$classNames[$position] = $newClassname;
}
}
$token[0] = implode('|', $classNames);
return implode(' ', $token); return implode(' ', $token);
} }

View file

@ -81,13 +81,14 @@ class Typo3Update_Sniffs_LegacyClassnames_InlineCommentSniff extends AbstractCla
/** /**
* As token contains more then just class name, we have to build new content ourself. * As token contains more then just class name, we have to build new content ourself.
* *
* @param string $classname * @param string $newClassname
* @param string $originalClassname
* @return string * @return string
*/ */
protected function getTokenForReplacement($classname) protected function getTokenForReplacement($newClassname, $originalClassname)
{ {
$token = preg_split('/\s+/', $this->originalTokenContent); $token = preg_split('/\s+/', $this->originalTokenContent);
$token[$this->getClassnamePosition($token)] = $classname; $token[$this->getClassnamePosition($token)] = $newClassname;
return implode(' ', $token); return implode(' ', $token);
} }

View file

@ -73,11 +73,12 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithMakeInstanceSniff ext
/** /**
* As token contains more then just class name, we have to build new content ourself. * As token contains more then just class name, we have to build new content ourself.
* *
* @param string $classname * @param string $newClassname
* @param string $originalClassname
* @return string * @return string
*/ */
protected function getTokenForReplacement($classname) protected function getTokenForReplacement($newClassname, $originalClassname)
{ {
return $this->getTokenReplacementForString($classname); return $this->getTokenReplacementForString($newClassname);
} }
} }

View file

@ -83,11 +83,12 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithObjectManagerSniff ex
/** /**
* As token contains more then just class name, we have to build new content ourself. * As token contains more then just class name, we have to build new content ourself.
* *
* @param string $classname * @param string $newClassname
* @param string $originalClassname
* @return string * @return string
*/ */
protected function getTokenForReplacement($classname) protected function getTokenForReplacement($newClassname, $originalClassname)
{ {
return $this->getTokenReplacementForString($classname); return $this->getTokenReplacementForString($newClassname);
} }
} }

View file

@ -72,11 +72,12 @@ class Typo3Update_Sniffs_LegacyClassnames_IsACallSniff extends AbstractClassname
/** /**
* As token contains more then just class name, we have to build new content ourself. * As token contains more then just class name, we have to build new content ourself.
* *
* @param string $classname * @param string $newClassname
* @param string $originalClassname
* @return string * @return string
*/ */
protected function getTokenForReplacement($classname) protected function getTokenForReplacement($newClassname, $originalClassname)
{ {
return $this->getTokenReplacementForString($classname); return $this->getTokenReplacementForString($newClassname);
} }
} }