Google\Cloud\Dev\Snippet\Parser\Parser::classExample PHP Method

classExample() public method

Example: $snippet = $parser->classExample(Parser::class);
public classExample ( string $class, integer | string $index ) : Snippet
$class string the name of the class
$index integer | string The index of the example to return.
return Snippet
    public function classExample($class, $index = 0)
    {
        $class = new ReflectionClass($class);
        $examples = $this->examplesFromClass($class);
        $result = array_filter($examples, function ($example) use($index) {
            return $example->index() == $index;
        });
        if (empty($result)) {
            throw new \Exception(sprintf('Given snippet index %d does not exist for class %s', $index, $class->getName()));
        }
        return current($result);
    }