public/assets/debug_bar/widgets/templates/widget.js   A
last analyzed

Complexity

Total Complexity 17
Complexity/F 3.4

Size

Lines of Code 69
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 17
c 0
b 0
f 0
dl 0
loc 69
rs 10
cc 0
nc 8
mnd 3
bc 16
fnc 5
bpm 3.2
cpm 3.4
noi 5

1 Function

Rating   Name   Duplication   Size   Complexity  
A PhpDebugBar.Widget.extend.render 0 51 1
1
(function($) {
2
3
    var csscls = PhpDebugBar.utils.makecsscls('phpdebugbar-widgets-');
0 ignored issues
show
Bug introduced by
The variable PhpDebugBar seems to be never declared. If this is a global, consider adding a /** global: PhpDebugBar */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
4
5
    /**
6
     * Widget for the displaying templates data
7
     *
8
     * Options:
9
     *  - data
10
     */
11
    var TemplatesWidget = PhpDebugBar.Widgets.TemplatesWidget = PhpDebugBar.Widget.extend({
0 ignored issues
show
Unused Code introduced by
The assignment to variable TemplatesWidget seems to be never used. Consider removing it.
Loading history...
12
13
        className: csscls('templates'),
14
15
        render: function() {
16
            this.$status = $('<div />').addClass(csscls('status')).appendTo(this.$el);
17
18
            this.$list = new  PhpDebugBar.Widgets.ListWidget({ itemRenderer: function(li, tpl) {
0 ignored issues
show
Bug introduced by
The variable PhpDebugBar seems to be never declared. If this is a global, consider adding a /** global: PhpDebugBar */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
19
                $('<span />').addClass(csscls('name')).text(tpl.name).appendTo(li);
20
                if (tpl.render_time_str) {
21
                    $('<span title="Render time" />').addClass(csscls('render-time')).text(tpl.render_time_str).appendTo(li);
22
                }
23
                if (tpl.memory_str) {
24
                    $('<span title="Memory usage" />').addClass(csscls('memory')).text(tpl.memory_str).appendTo(li);
25
                }
26
                if (typeof(tpl.param_count) != 'undefined') {
27
                    $('<span title="Parameter count" />').addClass(csscls('param-count')).text(tpl.param_count).appendTo(li);
28
                }
29
                if (typeof(tpl.type) != 'undefined' && tpl.type) {
30
                    $('<span title="Type" />').addClass(csscls('type')).text(tpl.type).appendTo(li);
31
                }
32
                if (tpl.params && !$.isEmptyObject(tpl.params)) {
33
                    var table = $('<table><tr><th colspan="2">Params</th></tr></table>').addClass(csscls('params')).appendTo(li);
34
                    for (var key in tpl.params) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
35
                        if (typeof tpl.params[key] !== 'function') {
36
                            table.append('<tr><td class="' + csscls('name') + '">' + key + '</td><td class="' + csscls('value') +
37
                            '"><pre><code>' + tpl.params[key] + '</code></pre></td></tr>');
38
                        }
39
                    }
40
                    li.css('cursor', 'pointer').click(function() {
41
                        if (table.is(':visible')) {
42
                            table.hide();
43
                        } else {
44
                            table.show();
45
                        }
46
                    });
47
                }
48
            }});
49
            this.$list.$el.appendTo(this.$el);
50
51
            this.bindAttr('data', function(data) {
52
                this.$list.set('data', data.templates);
53
                this.$status.empty();
54
55
                var sentence = data.sentence || "templates were rendered";
56
                $('<span />').text(data.templates.length + " " + sentence).appendTo(this.$status);
57
58
                if (data.accumulated_render_time_str) {
59
                    this.$status.append($('<span title="Accumulated render time" />').addClass(csscls('render-time')).text(data.accumulated_render_time_str));
60
                }
61
                if (data.memory_usage_str) {
62
                    this.$status.append($('<span title="Memory usage" />').addClass(csscls('memory')).text(data.memory_usage_str));
63
                }
64
            });
65
        }
66
67
    });
68
69
})(PhpDebugBar.$);
0 ignored issues
show
Bug introduced by
The variable PhpDebugBar seems to be never declared. If this is a global, consider adding a /** global: PhpDebugBar */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
70