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;
Namespace
Google \ Cloud \ Core \ Testing \ Snippet \ ParserMethods
__construct
classExample
Get a snippet from a class.
Example:
use Google\Cloud\Core\Testing\Snippet\Parser\Parser;
$snippet = $parser->classExample(Parser::class);
| Parameters | |
|---|---|
| Name | Description | 
| class | stringthe name of the class | 
| index | int|stringThe index of the example to return. | 
| Returns | |
|---|---|
| Type | Description | 
| Snippet | |
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);
| Parameters | |
|---|---|
| Name | Description | 
| class | stringThe name of the class. | 
| method | stringThe name of the method. | 
| index | intThe 0-indexed example to return. | 
| Returns | |
|---|---|
| Type | Description | 
| Snippet | |
examplesFromClass
Retrieve all examples from a class Doc Block.
Example:
$examples = $parser->examplesFromClass($parser);
| Parameter | |
|---|---|
| Name | Description | 
| class | object|ReflectionClassAn instance or reflector of the class to parse examples from. | 
| Returns | |
|---|---|
| Type | Description | 
| array | |
examplesFromMethod
Retrieve all examples from a method's Doc Block.
Example:
$examples = $parser->examplesFromMethod($parser, 'examplesFromMethod');
| Parameters | |
|---|---|
| Name | Description | 
| class | object|stringAn instance of the class to parse examples, or the name of the class. | 
| method | string|ReflectionMethodThe name of the method to parse examples from. | 
| Returns | |
|---|---|
| Type | Description | 
| array | |
allExamples
Retrieve all examples from a class and its methods.
Example:
$examples = $parser->allExamples($parser);
| Parameter | |
|---|---|
| Name | Description | 
| class | object|ReflectionClassAn instance or reflector of the class to parse. | 
| Returns | |
|---|---|
| Type | Description | 
| array | |
examples
Parse examples from a DocBlock object.
| Parameters | |
|---|---|
| Name | Description | 
| docBlock | phpDocumentor\Reflection\DocBlockThe DocBlock to parse | 
| fullyQualifiedName | mixed | 
| file | stringThe filename the docblock is in | 
| line | intThe line where the tested method or class is declared. | 
| magicMethods | array | 
| Returns | |
|---|---|
| Type | Description | 
| array | |
createIdentifier
Create identifier
| Parameters | |
|---|---|
| Name | Description | 
| fqn | string | 
| indexOrName | int|string | 
| Returns | |
|---|---|
| Type | Description | 
| string | |
Constants
SNIPPET_NAME_REGEX
Value: '/\/\/\s?\[snippet\=(\w{0,})\]/'