Generator::generate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Tonic\Component\ApiLayer\JsonRpcExtensions\Documentation;
4
5
use Tonic\Component\ApiLayer\JsonRpc\Method\MethodCollection;
6
7
/**
8
 * Generates documentation.
9
 */
10
class Generator
11
{
12
    /**
13
     * @var MetadataExtractor
14
     */
15
    private $metadataExtractor;
16
17
    /**
18
     * @var \Twig_Environment
19
     */
20
    private $twig;
21
22
    /**
23
     * @param \Tonic\Component\ApiLayer\JsonRpcExtensions\Documentation\MetadataExtractor $metadataExtractor
24
     * @param \Twig_Environment                                                           $twig
25
     */
26
    public function __construct(MetadataExtractor $metadataExtractor, \Twig_Environment $twig)
27
    {
28
        $this->metadataExtractor = $metadataExtractor;
29
        $this->twig = $twig;
30
    }
31
32
    /**
33
     * @param MethodCollection $methodCollection
34
     * @param string           $templateName
35
     *
36
     * @return string
37
     */
38
    public function generate(MethodCollection $methodCollection, $templateName = 'default.html.twig')
39
    {
40
        $metadata = $this->metadataExtractor->extract($methodCollection);
41
42
        return $this->twig->render($templateName, ['metadata' => $metadata]);
43
    }
44
}
45