validateTagName($name); $this->name = $name; $this->description = $description; } /** * Creates a new tag that represents any unknown tag type. * * @return static */ public static function create( string $body, string $name = '', ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null ) : self { Assert::stringNotEmpty($name); Assert::notNull($descriptionFactory); $description = $body !== '' ? $descriptionFactory->create($body, $context) : null; return new static($name, $description); } /** * Returns the tag as a serialized string */ public function __toString() : string { if ($this->description) { $description = $this->description->render(); } else { $description = ''; } return $description; } /** * Validates if the tag name matches the expected format, otherwise throws an exception. */ private function validateTagName(string $name) : void { if (!preg_match('/^' . StandardTagFactory::REGEX_TAGNAME . '$/u', $name)) { throw new InvalidArgumentException( 'The tag name "' . $name . '" is not wellformed. Tags may only consist of letters, underscores, ' . 'hyphens and backslashes.' ); } } }