function PhpdocSingleLineVarFixer::fix
File
-
vendor/
phar-io/ manifest/ tools/ php-cs-fixer.d/ PhpdocSingleLineVarFixer.php, line 40
Class
- PhpdocSingleLineVarFixer
- Main implementation taken from kubawerlos/php-cs-fixer-customere-fixers Copyright (c) 2018 Kuba Werłos
Namespace
PharIo\CSFixerCode
public function fix(\SplFileInfo $file, Tokens $tokens) : void {
foreach ($tokens as $index => $token) {
if (!$token->isGivenKind(T_DOC_COMMENT)) {
continue;
}
if (\stripos($token->getContent(), '@var') === false) {
continue;
}
if (preg_match('#^/\\*\\*[\\s\\*]+(@var[^\\r\\n]+)[\\s\\*]*\\*\\/$#u', $token->getContent(), $matches) !== 1) {
continue;
}
$newContent = '/** ' . \rtrim($matches[1]) . ' */';
if ($newContent === $token->getContent()) {
continue;
}
$tokens[$index] = new Token([
T_DOC_COMMENT,
$newContent,
]);
}
}