Hoa central
PhpdocThrows.php
Go to the documentation of this file.
1 <?php
2 
38 
39 use SplFileInfo;
44 
53 class PhpdocThrows extends AbstractFixer
54 {
55  public function fix(SplFileInfo $file, $content)
56  {
57  $tokens = Tokens::fromCode($content);
58 
59  foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
60  $docBlock = new DocBlock($token->getContent());
61  $annotations = $docBlock->getAnnotationsOfType('throw');
62 
63  if (empty($annotations)) {
64  continue;
65  }
66 
67  foreach ($annotations as $annotation) {
68  $line = $docBlock->getLine($annotation->getStart());
69  $line->setContent(
70  str_replace(
71  '@throw ',
72  '@throws',
73  $line->getContent()
74  )
75  );
76  }
77 
78  $token->setContent($docBlock->getContent());
79  }
80 
81  return $tokens->generateCode();
82  }
83 
84  public function getDescription()
85  {
86  return 'Replace `@throw` by `@throws`.';
87  }
88 
89  public function getName()
90  {
91  return 'phpdoc_throws';
92  }
93 
94  public function getLevel()
95  {
96  return FixerInterface::CONTRIB_LEVEL;
97  }
98 }
$content
Definition: Hoa.php:119