Completed
Push — master ( f1dd26...2cc827 )
by Dmitri
03:03
created

CodeExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethodSource() 0 3 1
A __construct() 0 3 1
A getClassSource() 0 3 1
A getName() 0 3 1
A getFunctions() 0 5 1
1
<?php
2
3
namespace AppBundle\Twig;
4
5
use AppBundle\CodeReader;
6
7
class CodeExtension extends \Twig_Extension
8
{
9
    private $reader;
10
11
    public function __construct(CodeReader $reader)
12
    {
13
        $this->reader = $reader;
14
    }
15
16
    public function getName()
17
    {
18
        return 'app_code';
19
    }
20
21
    public function getFunctions()
22
    {
23
        return [
24
            new \Twig_SimpleFunction('app_method_source', [$this, 'getMethodSource']),
25
            new \Twig_SimpleFunction('app_class_source', [$this, 'getClassSource']),
26
        ];
27
    }
28
29
    public function getMethodSource($spec, $bound = CodeReader::BOUND_FORM_BUILDER)
30
    {
31
        return $this->reader->readMethod($spec, $bound);
32
    }
33
34
    public function getClassSource($class)
35
    {
36
        return $this->reader->readClass($class);
37
    }
38
}
39