Hoa central
Public Member Functions | List of all members
Hoa\Devtools\Resource\PHPCSFixer\Fixer\PhpdocVar Class Reference
Inheritance diagram for Hoa\Devtools\Resource\PHPCSFixer\Fixer\PhpdocVar:

Public Member Functions

 fix (SplFileInfo $file, $content)
 
 getDescription ()
 
 getName ()
 
 getLevel ()
 

Detailed Description

Definition at line 61 of file PhpdocVar.php.

Member Function Documentation

Hoa\Devtools\Resource\PHPCSFixer\Fixer\PhpdocVar::fix ( SplFileInfo  $file,
  $content 
)

Definition at line 63 of file PhpdocVar.php.

64  {
65  $tokens = Tokens::fromCode($content);
66 
67  foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
68  $docBlock = new DocBlock($token->getContent());
69  $annotations = $docBlock->getAnnotationsOfType('var');
70 
71  if (empty($annotations)) {
72  continue;
73  }
74 
75  foreach ($annotations as $annotation) {
76  $line = $docBlock->getLine($annotation->getStart());
77  $lineContent = $line->getContent();
78 
79  if (0 !== preg_match('/^(?<before>.*?@var )(?<one>[^\s]+) (?<two>\w+)/', $lineContent, $matches)) {
80  if ('object' === $matches['two']) {
81  $line->setContent($matches['before'] . $matches['one'] . "\n");
82  } else {
83  $line->setContent($matches['before'] . $matches['two'] . "\n");
84  }
85  }
86  }
87 
88  $token->setContent($docBlock->getContent());
89  }
90 
91  return $tokens->generateCode();
92  }
$content
Definition: Hoa.php:119
Hoa\Devtools\Resource\PHPCSFixer\Fixer\PhpdocVar::getDescription ( )

Definition at line 94 of file PhpdocVar.php.

95  {
96  return '`@var` must contain one element.';
97  }
Hoa\Devtools\Resource\PHPCSFixer\Fixer\PhpdocVar::getLevel ( )

Definition at line 104 of file PhpdocVar.php.

105  {
106  return FixerInterface::CONTRIB_LEVEL;
107  }
Hoa\Devtools\Resource\PHPCSFixer\Fixer\PhpdocVar::getName ( )

Definition at line 99 of file PhpdocVar.php.

100  {
101  return 'phpdoc_var';
102  }

The documentation for this class was generated from the following file: