Task/Collect/MethodCollector.php
public function getMethodData(\ReflectionMethod $method) {
    $interface_method_data = [];

    $interface_method_data['name'] = $method->getName();

    // Methods may be in parent interfaces, so not all in the same file.
    $filename = $method->getFileName();
    $source = file($filename);
    $start_line = $method->getStartLine();

    // Trim whitespace from the front, as this will be indented.
    $interface_method_data['declaration'] = trim($source[$start_line - 1]);

    // Get the docblock for the method.
    $method_docblock_lines = explode("\n", $method->getDocComment());
    foreach ($method_docblock_lines as $line) {
      // Take the first actual docblock line to be the description.
      // Need to use preg_match() rather than match exactly to account for
      $matches = [];
      if (preg_match('@^ +\* (.+)@', $line, $matches)) {
        $interface_method_data['description'] = $matches[1];
        break;
      }
    }

    // Replace class typehints on method parameters with their full namespaced
    // versions, as typically these will be short class names. The PHPFile
    // generator will then take care of extracting namespaces and creating
    // import statements.
    // Get the typehint classes on parameters.
    $parameters = $method->getParameters();
    $search = [];
    $replace = [];
    foreach ($parameters as $parameter) {
      $parameter_hinted_class = $parameter->getClass();

      // Skip a parameter that doesn't have a class hint.
      if (is_null($parameter_hinted_class)) {
        continue;
      }

      // Create arrays for preg_replace() of search and replace strings.
      // Add a negative lookbehind for the backslash so we don't replace a
      // fully-qualified root-namespace typehint (such as \Iterator).
      // Add the space between the typehint and the parameter to help guard
      // against false replacements.
      $parameter_hinted_class_short_name = $parameter_hinted_class->getShortName();
      $search[] = "@(?<!\\\\){$parameter_hinted_class_short_name}(?= )@";

      // Prepend the initial '\'.
      $replace[] = '\\' . $parameter_hinted_class->getName();
    }

    $interface_method_data['declaration'] = preg_replace(
      $search,
      $replace,
      $interface_method_data['declaration']
    );

    return $interface_method_data;
  }
public function getMethodData(\ReflectionMethod $method) {
    $interface_method_data = [];

    $interface_method_data['name'] = $method->getName();

    // Methods may be in parent interfaces, so not all in the same file.
    $filename = $method->getFileName();
    $source = file($filename);
    $start_line = $method->getStartLine();

    // Trim whitespace from the front, as this will be indented.
    $interface_method_data['declaration'] = trim($source[$start_line - 1]);

    // Get the docblock for the method.
    $method_docblock_lines = explode("\n", $method->getDocComment());
    foreach ($method_docblock_lines as $line) {
      // Take the first actual docblock line to be the description.
      // Need to use preg_match() rather than match exactly to account for
      $matches = [];
      if (preg_match('@^ +\* (.+)@', $line, $matches)) {
        $interface_method_data['description'] = $matches[1];
        break;
      }
    }

    // Replace class typehints on method parameters with their full namespaced
    // versions, as typically these will be short class names. The PHPFile
    // generator will then take care of extracting namespaces and creating
    // import statements.
    // Get the typehint classes on parameters.
    $parameters = $method->getParameters();
    $search = [];
    $replace = [];
    foreach ($parameters as $parameter) {
      $parameter_hinted_class = $parameter->getClass();

      // Skip a parameter that doesn't have a class hint.
      if (is_null($parameter_hinted_class)) {
        continue;
      }

      // Create arrays for preg_replace() of search and replace strings.
      // Add a negative lookbehind for the backslash so we don't replace a
      // fully-qualified root-namespace typehint (such as \Iterator).
      // Add the space between the typehint and the parameter to help guard
      // against false replacements.
      $parameter_hinted_class_short_name = $parameter_hinted_class->getShortName();
      $search[] = "@(?<!\\\\){$parameter_hinted_class_short_name}(?= )@";

      // Prepend the initial '\'.
      $replace[] = '\\' . $parameter_hinted_class->getName();
    }

    $interface_method_data['declaration'] = preg_replace(
      $search,
      $replace,
      $interface_method_data['declaration']
    );

    return $interface_method_data;
  }
public function getMethodData ( \ ReflectionMethod $ method ) { $ interface_method_data = [ ] ; $ interface_method_data [ 'name' ] = $ method -> getName ( ) ; // Methods may be in parent interfaces, so not all in the same file. $ filename = $ method -> getFileName ( ) ; $ source = file ( $ filename ) ; $ start_line = $ method -> getStartLine ( ) ; // Trim whitespace from the front, as this will be indented. $ interface_method_data [ 'declaration' ] = trim ( $ source [ $ start_line - 1 ] ) ; // Get the docblock for the method. $ method_docblock_lines = explode ( "\n" , $ method -> getDocComment ( ) ) ; foreach ( $ method_docblock_lines as $ line ) { // Take the first actual docblock line to be the description. // Need to use preg_match() rather than match exactly to account for $ matches = [ ] ; if ( preg_match ( '@^ +\* (.+)@' , $ line , $ matches ) ) { $ interface_method_data [ 'description' ] = $ matches [ 1 ] ; break ; } } // Replace class typehints on method parameters with their full namespaced // versions, as typically these will be short class names. The PHPFile // generator will then take care of extracting namespaces and creating // import statements. // Get the typehint classes on parameters. $ parameters = $ method -> getParameters ( ) ; $ search = [ ] ; $ replace = [ ] ; foreach ( $ parameters as $ parameter ) { $ parameter_hinted_class = $ parameter -> getClass ( ) ; // Skip a parameter that doesn't have a class hint. if ( is_null ( $ parameter_hinted_class ) ) { continue ; } // Create arrays for preg_replace() of search and replace strings. // Add a negative lookbehind for the backslash so we don't replace a // fully-qualified root-namespace typehint (such as \Iterator). // Add the space between the typehint and the parameter to help guard // against false replacements. $ parameter_hinted_class_short_name = $ parameter_hinted_class -> getShortName ( ) ; $ search [ ] = "@(?<!\\\\){$parameter_hinted_class_short_name}(?= )@" ; // Prepend the initial '\'. $ replace [ ] = '\\' . $ parameter_hinted_class -> getName ( ) ; } $ interface_method_data [ 'declaration' ] = preg_replace ( $ search , $ replace , $ interface_method_data [ 'declaration' ] ) ; return $ interface_method_data ; }
Gets data for a method.

@param \ReflectionMethod $method
The reflection object for the method.

@return
An array containing:
- 'name: The name of the method.
- 'declaration': The function declaration line.
- 'description': The description from the method's docblock first line.
Gets data for a method .