Completed
Pull Request — master (#546)
by Richard
09:47
created

Kint_Renderer_Rich_Table::render()   F

Complexity

Conditions 23
Paths 884

Size

Total Lines 93
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 23
eloc 64
nc 884
nop 1
dl 0
loc 93
rs 2.2656
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
class Kint_Renderer_Rich_Table extends Kint_Renderer_Rich_Plugin
4
{
5
    public static $respect_str_length = true;
6
7
    public function render($r)
8
    {
9
        $out = '<pre><table><thead><tr><th></th>';
10
11
        $firstrow = reset($r->contents);
12
13
        foreach ($firstrow->value->contents as $field) {
14
            $out .= '<th>'.$this->renderer->escape($field->name).'</th>';
15
        }
16
17
        $out .= '</tr></thead><tbody>';
18
19
        foreach ($r->contents as $row) {
20
            $out .= '<tr><th>';
21
            $out .= $this->renderer->escape($row->name);
22
            $out .= '</th>';
23
24
            foreach ($row->value->contents as $field) {
25
                $out .= '<td';
26
                $type = '';
27
                $size = '';
28
                $ref = '';
29
30
                if (($s = $field->getType()) !== null) {
31
                    $type = $this->renderer->escape($s);
32
33
                    if ($field->reference) {
34
                        $ref = '&amp;';
35
                        $type = $ref.$type;
36
                    }
37
38
                    if (($s = $field->getSize()) !== null) {
39
                        $size .= ' ('.$this->renderer->escape($s).')';
40
                    }
41
                }
42
43
                if ($type) {
44
                    $out .= ' title="'.$type.$size.'"';
45
                }
46
47
                $out .= '>';
48
49
                switch ($field->type) {
50
                    case 'boolean':
51
                        $out .= $field->value->contents ? '<var>'.$ref.'true</var>' : '<var>'.$ref.'false</var>';
52
                        break;
53
                    case 'integer':
54
                    case 'double':
55
                        $out .= (string) $field->value->contents;
56
                        break;
57
                    case 'null':
58
                        $out .= '<var>'.$ref.'null</var>';
59
                        break;
60
                    case 'string':
61
                        $val = $field->value->contents;
62
                        if (Kint_Renderer_Rich::$strlen_max && self::$respect_str_length && Kint_Object_Blob::strlen($val) > Kint_Renderer_Rich::$strlen_max) {
63
                            $val = substr($val, 0, Kint_Renderer_Rich::$strlen_max).'...';
64
                        }
65
66
                        $out .= $this->renderer->escape($val);
67
                        break;
68
                    case 'array':
69
                        $out .= '<var>'.$ref.'array</var>'.$size;
70
                        break;
71
                    case 'object':
72
                        $out .= '<var>'.$ref.$this->renderer->escape($field->classname).'</var>'.$size;
73
                        break;
74
                    case 'resource':
75
                        $out .= '<var>'.$ref.'resource</var>';
76
                        break;
77
                    default:
78
                        $out .= '<var>'.$ref.'unknown</var>';
79
                        break;
80
                }
81
82
                if (in_array('blacklist', $field->hints)) {
83
                    $out .= ' <var>Blacklisted</var>';
84
                } elseif (in_array('recursion', $field->hints)) {
85
                    $out .= ' <var>Recursion</var>';
86
                } elseif (in_array('depth_limit', $field->hints)) {
87
                    $out .= ' <var>Depth Limit</var>';
88
                }
89
90
                $out .= '</td>';
91
            }
92
93
            $out .= '</tr>';
94
        }
95
96
        $out .= '</tbody></table></pre>';
97
98
        return $out;
99
    }
100
}
101