Reference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class Parser.
A class for parsing code snippets from a class and its methods.
Example:
use Google\Cloud\Core\Testing\Snippet\Parser\Parser;
$parser = new Parser;
Methods
__construct
classExample
Get a snippet from a class.
Example:
use Google\Cloud\Core\Testing\Snippet\Parser\Parser;
$snippet = $parser->classExample(Parser::class);
class
string
the name of the class
index
int|string
The index of the example to return.
methodExample
Get a snippet from a method.
Example:
use Google\Cloud\Core\Testing\Snippet\Parser\Parser;
$snippet = $parser->methodExample(Parser::class, 'methodExample');
use Google\Cloud\Core\Testing\Snippet\Parser\Parser;
// Get the 2nd example (index=1)
$snippet = $parser->methodExample(Parser::class, 'methodExample', 1);
class
string
The name of the class.
method
string
The name of the method.
index
int
The 0-indexed example to return.
examplesFromClass
Retrieve all examples from a class Doc Block.
Example:
$examples = $parser->examplesFromClass($parser);
class
object| ReflectionClass
An instance or reflector of the class to parse examples from.
array
examplesFromMethod
Retrieve all examples from a method's Doc Block.
Example:
$examples = $parser->examplesFromMethod($parser, 'examplesFromMethod');
class
object|string
An instance of the class to parse examples, or the name of the class.
method
string| ReflectionMethod
The name of the method to parse examples from.
array
allExamples
Retrieve all examples from a class and its methods.
Example:
$examples = $parser->allExamples($parser);
class
object| ReflectionClass
An instance or reflector of the class to parse.
array
examples
Parse examples from a DocBlock object.
docBlock
phpDocumentor\Reflection\DocBlock
The DocBlock to parse
fullyQualifiedName
mixed
file
string
The filename the docblock is in
line
int
The line where the tested method or class is declared.
magicMethods
array
array
createIdentifier
Create identifier
fqn
string
indexOrName
int|string
string
Constants
SNIPPET_NAME_REGEX
Value: '/\\/\\/\\s?\\[snippet\\=(\\w{0,})\\]/'