Google Cloud PHP shared dependency, providing functionality useful to all components. Client - Class Parser (1.50.0)

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);
Parameters
NameDescription
class string

the name of the class

index int|string

The index of the example to return.

Returns
TypeDescription
Google\Cloud\Core\Testing\Snippet\Parser\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
NameDescription
class string

The name of the class.

method string

The name of the method.

index int

The 0-indexed example to return.

Returns
TypeDescription
Google\Cloud\Core\Testing\Snippet\Parser\Snippet

examplesFromClass

Retrieve all examples from a class Doc Block.

Example:

$examples = $parser->examplesFromClass($parser);
Parameter
NameDescription
class object|ReflectionClass

An instance or reflector of the class to parse examples from.

Returns
TypeDescription
array

examplesFromMethod

Retrieve all examples from a method's Doc Block.

Example:

$examples = $parser->examplesFromMethod($parser, 'examplesFromMethod');
Parameters
NameDescription
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.

Returns
TypeDescription
array

allExamples

Retrieve all examples from a class and its methods.

Example:

$examples = $parser->allExamples($parser);
Parameter
NameDescription
class object|ReflectionClass

An instance or reflector of the class to parse.

Returns
TypeDescription
array

examples

Parse examples from a DocBlock object.

Parameters
NameDescription
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
Returns
TypeDescription
array

createIdentifier

Create identifier

Parameters
NameDescription
fqn string
indexOrName int|string
Returns
TypeDescription
string

Constants

SNIPPET_NAME_REGEX

Value: '/\\/\\/\\s?\\[snippet\\=(\\w{0,})\\]/'