Hoa central
Copyright.php
Go to the documentation of this file.
1 <?php
2 
38 
39 use SplFileInfo;
44 
53 class Copyright extends AbstractFixer
54 {
55  public function fix(SplFileInfo $file, $content)
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  }
95 
96  public function getDescription()
97  {
98  return 'Keep copyright up-to-date.';
99  }
100 
101  public function getName()
102  {
103  return 'copyright';
104  }
105 
106  public function getLevel()
107  {
108  return FixerInterface::CONTRIB_LEVEL;
109  }
110 }
$content
Definition: Hoa.php:119