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

Public Member Functions

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

Detailed Description

Class .

Keep copyright up-to-date.

Definition at line 53 of file Copyright.php.

Member Function Documentation

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

Definition at line 55 of file Copyright.php.

56  {
57  $tokens = Tokens::fromCode($content);
58  $thisYear = date('Y');
59 
60  foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
61  $token->setContent(
62  preg_replace_callback(
63  '/Copyright © (?<firstYear>\d{4})-\d{4}, [^\.]+/',
64  function ($matches) use ($thisYear) {
65 
66  return
67  'Copyright © ' .
68  $matches['firstYear'] . '-' . $thisYear . ', ' .
69  'Hoa community';
70  },
71  $token->getContent()
72  )
73  );
74 
75  $docBlock = new DocBlock($token->getContent());
76  $annotations = $docBlock->getAnnotationsOfType('copyright');
77 
78  if (empty($annotations)) {
79  continue;
80  }
81 
82  foreach ($annotations as $annotation) {
83  $line = $docBlock->getLine($annotation->getStart());
84  $line->setContent(
85  ' * @copyright Copyright © 2007-' . $thisYear .
86  ' Hoa community' . "\n"
87  );
88  }
89 
90  $token->setContent($docBlock->getContent());
91  }
92 
93  return $tokens->generateCode();
94  }
$content
Definition: Hoa.php:119
Hoa\Devtools\Resource\PHPCSFixer\Fixer\Copyright::getDescription ( )

Definition at line 96 of file Copyright.php.

97  {
98  return 'Keep copyright up-to-date.';
99  }
Hoa\Devtools\Resource\PHPCSFixer\Fixer\Copyright::getLevel ( )

Definition at line 106 of file Copyright.php.

107  {
108  return FixerInterface::CONTRIB_LEVEL;
109  }
Hoa\Devtools\Resource\PHPCSFixer\Fixer\Copyright::getName ( )

Definition at line 101 of file Copyright.php.

102  {
103  return 'copyright';
104  }

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