Tag.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This file is part of the PHP CS utility.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\CS\DocBlock;
  11. /**
  12. * This represents a tag, as defined by the proposed PSR PHPDoc standard.
  13. *
  14. * @author Graham Campbell <graham@mineuk.com>
  15. */
  16. class Tag
  17. {
  18. /**
  19. * All the tags defined by the proposed PSR PHPDoc standard.
  20. *
  21. * @var string[]
  22. */
  23. private static $tags = array(
  24. 'api', 'author', 'category', 'copyright', 'deprecated', 'example',
  25. 'global', 'internal', 'license', 'link', 'method', 'package', 'param',
  26. 'property', 'return', 'see', 'since', 'struct', 'subpackage', 'throws',
  27. 'todo', 'typedef', 'uses', 'var', 'version',
  28. );
  29. /**
  30. * The tag name.
  31. *
  32. * @var string
  33. */
  34. private $name;
  35. /**
  36. * Create a new tag instance.
  37. *
  38. * @param string $content
  39. */
  40. public function __construct($content)
  41. {
  42. preg_match_all('/@[a-zA-Z0-9_]+/', $content, $matches);
  43. if (isset($matches[0][0])) {
  44. $this->name = strtolower(ltrim($matches[0][0], '@'));
  45. } else {
  46. $this->name = 'other';
  47. }
  48. }
  49. /**
  50. * Get the tag name.
  51. *
  52. * This may be "param", or "return", etc.
  53. *
  54. * @return string
  55. */
  56. public function getName()
  57. {
  58. return $this->name;
  59. }
  60. /**
  61. * Is the tag a known tag.
  62. *
  63. * This is defined by if it exists in the proposed PSR PHPDoc standard.
  64. *
  65. * @return bool
  66. */
  67. public function valid()
  68. {
  69. return in_array($this->name, self::$tags, true);
  70. }
  71. }