ExtjsExtension   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 92.86%

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 9
c 4
b 1
f 2
lcom 1
cbo 3
dl 0
loc 71
ccs 26
cts 28
cp 0.9286
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setGenerator() 0 3 1
A setRouter() 0 3 1
A getName() 0 4 1
A getFilters() 0 5 1
A getFunctions() 0 6 1
A injectModel() 0 15 3
A ucfirst() 0 4 1
1
<?php
2
namespace Tpg\ExtjsBundle\Twig;
3
4
class ExtjsExtension extends \Twig_Extension {
5
6
    protected $generator;
7
    protected $router;
8
9
    /**
10
     * DI for ExtJS Generator
11
     * @param $generator
12
     */
13 3
    public function setGenerator($generator) {
14 3
        $this->generator = $generator;
15 3
    }
16
17
    /**
18
     * DI for Router
19
     * @param $router
20
     */
21 3
    public function setRouter($router) {
22 3
        $this->router = $router;
23 3
    }
24
25
    /**
26
     * Returns the name of the extension.
27
     *
28
     * @return string The extension name
29
     */
30 3
    public function getName()
31
    {
32 3
        return 'extjs';
33
    }
34
35 2
    public function getFilters() {
36
        return array(
37 2
            new \Twig_SimpleFilter('ucfirst', array($this, 'ucfirst')),
38 2
        );
39
    }
40
41 2
    public function getFunctions()
42
    {
43
        return array(
44 2
            new \Twig_SimpleFunction('extjs_model', array($this, 'injectModel'), array('is_safe' => array('all'))),
45 2
        );
46
    }
47
48
    /**
49
     * Inject ExtJs Model into the DOM.
50
     *
51
     * @param boolean $injection Produce ExtJS model code on the page directly?
0 ignored issues
show
Bug introduced by
There is no parameter named $injection. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
52
     * @param string $model Model Name.
0 ignored issues
show
Bug introduced by
There is no parameter named $model. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
53
     */
54 2
    public function injectModel() {
55 2
        $params = func_get_args();
56 2
        $injection = array_shift($params);
57 2
        if ($injection == false) {
58 1
            $url = $this->router->generate('extjs_generate_model', array('model'=>$params), false);
59 1
            return "<script type='text/javascript' src='$url'></script>";
60
        } else {
61 1
            $code = '';
62 1
            foreach ($params as $model) {
63 1
                $model = str_replace(".", "\\", $model);
64 1
                $code .= $this->generator->generateMarkupForEntity($model);
65 1
            }
66 1
            return $code;
67
        }
68
    }
69
70
    public function ucfirst($string) {
71
        return ucfirst($string);
72
73
    }
74
}