/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Deprecated.php

https://bitbucket.org/alan_cordova/api-sb-map · PHP · 97 lines · 54 code · 12 blank · 31 comment · 2 complexity · 9f948aa2963bd73fa9badee9e53ffc19 MD5 · raw file

  1. <?php
  2. /**
  3. * This file is part of phpDocumentor.
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
  9. * @license http://www.opensource.org/licenses/mit-license.php MIT
  10. * @link http://phpdoc.org
  11. */
  12. namespace phpDocumentor\Reflection\DocBlock\Tags;
  13. use phpDocumentor\Reflection\DocBlock\Description;
  14. use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
  15. use phpDocumentor\Reflection\Types\Context as TypeContext;
  16. use Webmozart\Assert\Assert;
  17. /**
  18. * Reflection class for a {@}deprecated tag in a Docblock.
  19. */
  20. final class Deprecated extends BaseTag implements Factory\StaticMethod
  21. {
  22. protected $name = 'deprecated';
  23. /**
  24. * PCRE regular expression matching a version vector.
  25. * Assumes the "x" modifier.
  26. */
  27. const REGEX_VECTOR = '(?:
  28. # Normal release vectors.
  29. \d\S*
  30. |
  31. # VCS version vectors. Per PHPCS, they are expected to
  32. # follow the form of the VCS name, followed by ":", followed
  33. # by the version vector itself.
  34. # By convention, popular VCSes like CVS, SVN and GIT use "$"
  35. # around the actual version vector.
  36. [^\s\:]+\:\s*\$[^\$]+\$
  37. )';
  38. /** @var string The version vector. */
  39. private $version = '';
  40. public function __construct($version = null, Description $description = null)
  41. {
  42. Assert::nullOrStringNotEmpty($version);
  43. $this->version = $version;
  44. $this->description = $description;
  45. }
  46. /**
  47. * @return static
  48. */
  49. public static function create($body, DescriptionFactory $descriptionFactory = null, TypeContext $context = null)
  50. {
  51. Assert::nullOrString($body);
  52. if (empty($body)) {
  53. return new static();
  54. }
  55. $matches = [];
  56. if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) {
  57. return new static(
  58. null,
  59. null !== $descriptionFactory ? $descriptionFactory->create($body, $context) : null
  60. );
  61. }
  62. return new static(
  63. $matches[1],
  64. $descriptionFactory->create(isset($matches[2]) ? $matches[2] : '', $context)
  65. );
  66. }
  67. /**
  68. * Gets the version section of the tag.
  69. *
  70. * @return string
  71. */
  72. public function getVersion()
  73. {
  74. return $this->version;
  75. }
  76. /**
  77. * Returns a string representation for this tag.
  78. *
  79. * @return string
  80. */
  81. public function __toString()
  82. {
  83. return $this->version . ($this->description ? ' ' . $this->description->render() : '');
  84. }
  85. }