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

1.72.2 (latest) 1.72.1 1.71.2 1.70.0 1.69.0 1.68.2 1.67.0 1.66.0 1.65.0 1.64.3 1.63.0 1.62.3 1.61.0 1.60.1 1.59.1 1.58.2 1.53.0 1.52.11 1.51.2 1.50.0 1.49.3 1.48.1 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 \\ 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** ||
|---|---|
| **Name** | **Description** |
| `class` | `string` the name of the class |
| `index` | `int|string` The index of the example to return. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/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** ||
|---|---|
| **Name** | **Description** |
| `class` | `string` The name of the class. |
| `method` | `string` The name of the method. |
| `index` | `int` The 0-indexed example to return. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Testing.Snippet.Parser.Snippet` |   |

### examplesFromClass

Retrieve all examples from a class Doc Block.

Example:

    $examples = $parser->examplesFromClass($parser);

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `class` | `object|ReflectionClass` An 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|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** ||
|---|---|
| **Type** | **Description** |
| `array` |   |

### allExamples

Retrieve all examples from a class and its methods.

Example:

    $examples = $parser->allExamples($parser);

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `class` | `object|ReflectionClass` An 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\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** ||
|---|---|
| **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,})\]/'