/** * {@inheritdoc} */ public function setContent($content) { Tag::setContent($content); if (preg_match('/^ # File component (?: # File path in quotes \\"([^\\"]+)\\" | # File URI (\\S+) ) # Remaining content (parsed by SourceTag) (?:\\s+(.*))? $/sux', $this->description, $matches)) { if ('' !== $matches[1]) { $this->setFilePath($matches[1]); } else { $this->setFileURI($matches[2]); } if (isset($matches[3])) { parent::setContent($matches[3]); } else { $this->setDescription(''); } $this->content = $content; } return $this; }
/** * {@inheritdoc} */ public function setContent($content) { parent::setContent($content); $parts = preg_split('/\\s+/Su', $this->description, 2); $this->link = $parts[0]; $this->setDescription(isset($parts[1]) ? $parts[1] : $parts[0]); $this->content = $content; return $this; }
/** * {@inheritdoc} */ public function setContent($content) { parent::setContent($content); $parts = preg_split('/\\s+/Su', $this->description, 2); // any output is considered a type $this->refers = $parts[0]; $this->setDescription(isset($parts[1]) ? $parts[1] : ''); $this->content = $content; return $this; }
/** * {@inheritdoc} */ public function setContent($content) { Tag::setContent($content); // 1. none or more whitespace // 2. optionally the keyword "static" followed by whitespace // 3. optionally a word with underscores followed by whitespace : as // type for the return value // 4. then optionally a word with underscores followed by () and // whitespace : as method name as used by phpDocumentor // 5. then a word with underscores, followed by ( and any character // until a ) and whitespace : as method name with signature // 6. any remaining text : as description if (preg_match('/^ # Static keyword # Declates a static method ONLY if type is also present (?: (static) \\s+ )? # Return type (?: ([\\w\\|_\\\\]+) \\s+ )? # Legacy method name (not captured) (?: [\\w_]+\\(\\)\\s+ )? # Method name ([\\w\\|_\\\\]+) # Arguments \\(([^\\)]*)\\) \\s* # Description (.*) $/sux', $this->description, $matches)) { list(, $static, $this->type, $this->method_name, $this->arguments, $this->description) = $matches; if ($static) { if (!$this->type) { $this->type = 'static'; } else { $this->isStatic = true; } } else { if (!$this->type) { $this->type = 'void'; } } $this->parsedDescription = null; } return $this; }
/** * {@inheritdoc} */ public function setContent($content) { parent::setContent($content); if (preg_match('/^ # The version vector (' . self::REGEX_VECTOR . ') \\s* # The description (.+)? $/sux', $this->description, $matches)) { $this->version = $matches[1]; $this->setDescription(isset($matches[2]) ? $matches[2] : ''); $this->content = $content; } return $this; }
/** * {@inheritdoc} */ public function setContent($content) { Tag::setContent($content); $parts = preg_split('/(\\s+)/Su', $this->description, 3, PREG_SPLIT_DELIM_CAPTURE); // if the first item that is encountered is not a variable; it is a type if (isset($parts[0]) && strlen($parts[0]) > 0 && $parts[0][0] !== '$') { $this->type = array_shift($parts); array_shift($parts); } // if the next item starts with a $ or ...$ it must be the variable name if (isset($parts[0]) && strlen($parts[0]) > 0 && ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$')) { $this->variableName = array_shift($parts); array_shift($parts); if (substr($this->variableName, 0, 3) === '...') { $this->isVariadic = true; $this->variableName = substr($this->variableName, 3); } } $this->setDescription(implode('', $parts)); $this->content = $content; return $this; }
/** * {@inheritdoc} */ public function setContent($content) { parent::setContent($content); if (preg_match('/^ # Starting line ([1-9]\\d*) \\s* # Number of lines (?: ((?1)) \\s+ )? # Description (.*) $/sux', $this->description, $matches)) { $this->startingLine = (int) $matches[1]; if (isset($matches[2]) && '' !== $matches[2]) { $this->lineCount = (int) $matches[2]; } $this->setDescription($matches[3]); $this->content = $content; } return $this; }
/** * @param \ReflectionMethod $method * @param string $alias * @param \ReflectionClass $class * @param string|null $methodName * @param array $interfaces */ public function __construct(\ReflectionMethod $method, $alias, $class, $methodName = null, $interfaces = array()) { $this->method = $method; $this->interfaces = $interfaces; $this->name = $methodName ?: $method->name; $this->namespace = $method->getDeclaringClass()->getNamespaceName(); //Create a DocBlock and serializer instance $this->phpdoc = new DocBlock($method, new Context($this->namespace)); //Normalize the description and inherit the docs from parents/interfaces try { $this->normalizeParams($this->phpdoc); $this->normalizeReturn($this->phpdoc); $this->normalizeDescription($this->phpdoc); } catch (\Exception $e) { } //Get the parameters, including formatted default values $this->getParameters($method); //Make the method static $this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc)); //Reference the 'real' function in the declaringclass $declaringClass = $method->getDeclaringClass(); $this->declaringClassName = '\\' . ltrim($declaringClass->name, '\\'); $this->root = '\\' . ltrim($class->getName(), '\\'); }
/** * @param string $class * @return string */ protected function createPhpDocs($class) { $reflection = new \ReflectionClass($class); $namespace = $reflection->getNamespaceName(); $classname = $reflection->getShortName(); $originalDoc = $reflection->getDocComment(); if ($this->reset) { $phpdoc = new DocBlock('', new Context($namespace)); } else { $phpdoc = new DocBlock($reflection, new Context($namespace)); } if (!$phpdoc->getText()) { $phpdoc->setText($class); } $properties = array(); $methods = array(); foreach ($phpdoc->getTags() as $tag) { $name = $tag->getName(); if ($name == "property" || $name == "property-read" || $name == "property-write") { $properties[] = $tag->getVariableName(); } elseif ($name == "method") { $methods[] = $tag->getMethodName(); } } foreach ($this->properties as $name => $property) { $name = "\${$name}"; if (in_array($name, $properties)) { continue; } if ($property['read'] && $property['write']) { $attr = 'property'; } elseif ($property['write']) { $attr = 'property-write'; } else { $attr = 'property-read'; } if ($this->hasCamelCaseModelProperties()) { $name = Str::camel($name); } $tagLine = trim("@{$attr} {$property['type']} {$name} {$property['comment']}"); $tag = Tag::createInstance($tagLine, $phpdoc); $phpdoc->appendTag($tag); } foreach ($this->methods as $name => $method) { if (in_array($name, $methods)) { continue; } $arguments = implode(', ', $method['arguments']); $tag = Tag::createInstance("@method static {$method['type']} {$name}({$arguments})", $phpdoc); $phpdoc->appendTag($tag); } if ($this->write && !$phpdoc->getTagsByName('mixin')) { $phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc)); } $serializer = new DocBlockSerializer(); $serializer->getDocComment($phpdoc); $docComment = $serializer->getDocComment($phpdoc); if ($this->write) { $filename = $reflection->getFileName(); $contents = $this->files->get($filename); if ($originalDoc) { $contents = str_replace($originalDoc, $docComment, $contents); } else { $needle = "class {$classname}"; $replace = "{$docComment}\nclass {$classname}"; $pos = strpos($contents, $needle); if ($pos !== false) { $contents = substr_replace($contents, $replace, $pos, strlen($needle)); } } if ($this->files->put($filename, $contents)) { $this->info('Written new phpDocBlock to ' . $filename); } } $output = "namespace {$namespace}{\n{$docComment}\n\tclass {$classname} extends \\Eloquent {}\n}\n\n"; return $output; }
/** * Test that the \Barryvdh\Reflection\DocBlock\Tag\VarTag can * understand the @var doc block. * * @param string $type * @param string $content * @param string $exDescription * * @covers \Barryvdh\Reflection\DocBlock\Tag * @dataProvider provideDataForConstuctor * * @return void */ public function testConstructorParesInputsIntoCorrectFields($type, $content, $exDescription) { $tag = new Tag($type, $content); $this->assertEquals($type, $tag->getName()); $this->assertEquals($content, $tag->getContent()); $this->assertEquals($exDescription, $tag->getDescription()); }
/** * Appends a tag at the end of the list of tags. * * @param Tag $tag The tag to add. * * @return Tag The newly added tag. * * @throws \LogicException When the tag belongs to a different DocBlock. */ public function appendTag(Tag $tag) { if (null === $tag->getDocBlock()) { $tag->setDocBlock($this); } if ($tag->getDocBlock() === $this) { $this->tags[] = $tag; } else { throw new \LogicException('This tag belongs to a different DocBlock object.'); } return $tag; }
/** * Returns the parsed text of this description. * * @return array An array of strings and tag objects, in the order they * occur within the description. */ public function getParsedContents() { if (null === $this->parsedContents) { $this->parsedContents = preg_split('/\\{ # "{@}" is not a valid inline tag. This ensures that # we do not treat it as one, but treat it literally. (?!@\\}) # We want to capture the whole tag line, but without the # inline tag delimiters. (\\@ # Match everything up to the next delimiter. [^{}]* # Nested inline tag content should not be captured, or # it will appear in the result separately. (?: # Match nested inline tags. (?: # Because we did not catch the tag delimiters # earlier, we must be explicit with them here. # Notice that this also matches "{}", as a way # to later introduce it as an escape sequence. \\{(?1)?\\} | # Make sure we match hanging "{". \\{ ) # Match content after the nested inline tag. [^{}]* )* # If there are more inline tags, match them as well. # We use "*" since there may not be any nested inline # tags. ) \\}/Sux', $this->contents, null, PREG_SPLIT_DELIM_CAPTURE); $count = count($this->parsedContents); for ($i = 1; $i < $count; $i += 2) { $this->parsedContents[$i] = Tag::createInstance($this->parsedContents[$i], $this->docblock); } //In order to allow "literal" inline tags, the otherwise invalid //sequence "{@}" is changed to "@", and "{}" is changed to "}". //See unit tests for examples. for ($i = 0; $i < $count; $i += 2) { $this->parsedContents[$i] = str_replace(array('{@}', '{}'), array('@', '}'), $this->parsedContents[$i]); } } return $this->parsedContents; }