BUGFIX: Allow multiple type hints in php docs
* Respect possible separation by "|" and handle each of them. Resolves: #48
This commit is contained in:
parent
2d33832a79
commit
f3e708f5e0
6 changed files with 36 additions and 21 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue