You are here

class MethodTag in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/phpdocumentor/reflection-docblock/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php \phpDocumentor\Reflection\DocBlock\Tag\MethodTag

Reflection class for a @method in a Docblock.

@author Mike van Riel <mike.vanriel@naenius.com> @license http://www.opensource.org/licenses/mit-license.php MIT @link http://phpdoc.org

Hierarchy

  • class \phpDocumentor\Reflection\DocBlock\Tag implements \phpDocumentor\Reflection\DocBlock\Reflector
    • class \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag
      • class \phpDocumentor\Reflection\DocBlock\Tag\MethodTag

Expanded class hierarchy of MethodTag

File

vendor/phpdocumentor/reflection-docblock/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php, line 24

Namespace

phpDocumentor\Reflection\DocBlock\Tag
View source
class MethodTag extends ReturnTag {

  /** @var string */
  protected $method_name = '';

  /** @var string */
  protected $arguments = '';

  /** @var bool */
  protected $isStatic = false;

  /**
   * {@inheritdoc}
   */
  public function getContent() {
    if (null === $this->content) {
      $this->content = '';
      if ($this->isStatic) {
        $this->content .= 'static ';
      }
      $this->content .= $this->type . " {$this->method_name}({$this->arguments}) " . $this->description;
    }
    return $this->content;
  }

  /**
   * {@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;
  }

  /**
   * Sets the name of this method.
   *
   * @param string $method_name The name of the method.
   *
   * @return $this
   */
  public function setMethodName($method_name) {
    $this->method_name = $method_name;
    $this->content = null;
    return $this;
  }

  /**
   * Retrieves the method name.
   *
   * @return string
   */
  public function getMethodName() {
    return $this->method_name;
  }

  /**
   * Sets the arguments for this method.
   *
   * @param string $arguments A comma-separated arguments line.
   *
   * @return void
   */
  public function setArguments($arguments) {
    $this->arguments = $arguments;
    $this->content = null;
    return $this;
  }

  /**
   * Returns an array containing each argument as array of type and name.
   *
   * Please note that the argument sub-array may only contain 1 element if no
   * type was specified.
   *
   * @return string[]
   */
  public function getArguments() {
    if (empty($this->arguments)) {
      return array();
    }
    $arguments = explode(',', $this->arguments);
    foreach ($arguments as $key => $value) {
      $arguments[$key] = explode(' ', trim($value));
    }
    return $arguments;
  }

  /**
   * Checks whether the method tag describes a static method or not.
   *
   * @return bool TRUE if the method declaration is for a static method, FALSE
   *     otherwise.
   */
  public function isStatic() {
    return $this->isStatic;
  }

  /**
   * Sets a new value for whether the method is static or not.
   *
   * @param bool $isStatic The new value to set.
   *
   * @return $this
   */
  public function setIsStatic($isStatic) {
    $this->isStatic = $isStatic;
    $this->content = null;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MethodTag::$arguments protected property @var string
MethodTag::$isStatic protected property @var bool
MethodTag::$method_name protected property @var string
MethodTag::getArguments public function Returns an array containing each argument as array of type and name.
MethodTag::getContent public function Gets the content of this tag. Overrides ReturnTag::getContent
MethodTag::getMethodName public function Retrieves the method name.
MethodTag::isStatic public function Checks whether the method tag describes a static method or not.
MethodTag::setArguments public function Sets the arguments for this method.
MethodTag::setContent public function Sets the content of this tag. Overrides ReturnTag::setContent
MethodTag::setIsStatic public function Sets a new value for whether the method is static or not.
MethodTag::setMethodName public function Sets the name of this method.
ReturnTag::$type protected property @var string The raw type component.
ReturnTag::$types protected property @var Collection The parsed type component.
ReturnTag::getType public function Returns the type section of the variable.
ReturnTag::getTypes public function Returns the unique types of the variable.
ReturnTag::getTypesCollection protected function Returns the type collection.
Tag::$content protected property When set to NULL, it means it needs to be regenerated.
Tag::$description protected property @var string Description of the content of this tag
Tag::$docblock protected property @var DocBlock The DocBlock which this tag belongs to.
Tag::$location protected property @var Location Location of the tag.
Tag::$parsedDescription protected property When set to NULL, it means it needs to be regenerated.
Tag::$tag protected property @var string Name of the tag
Tag::$tagHandlerMappings private static property handles it as an array value. The class is expected to inherit this class.
Tag::createInstance final public static function Factory method responsible for instantiating the correct sub type.
Tag::export public static function Builds a string representation of this object.
Tag::getDescription public function Gets the description component of this tag.
Tag::getDocBlock public function Gets the docblock this tag belongs to.
Tag::getLocation public function Gets the location of the tag.
Tag::getName public function Gets the name of this tag.
Tag::getParsedDescription public function Gets the parsed text of this description.
Tag::REGEX_TAGNAME constant PCRE regular expression matching a tag name.
Tag::registerTagHandler final public static function Registers a handler for tags.
Tag::setDescription public function Sets the description component of this tag.
Tag::setDocBlock public function Sets the docblock this tag belongs to.
Tag::setLocation public function Sets the location of the tag.
Tag::setName public function Sets the name of this tag.
Tag::__construct public function Parses a tag and populates the member variables.
Tag::__toString public function Returns the tag as a serialized string