Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PhpdocSingleLineVarFixer.php

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\CSFixer

Code

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,
        ]);
    }
}
RSS feed
Powered by Drupal