Passed
Push — master ( ba645d...9eba8c )
by Michael
07:09 queued 43s
created

TablePlugin::renderTab()   F

Complexity

Conditions 24
Paths 964

Size

Total Lines 96
Code Lines 66

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 24
eloc 66
c 0
b 0
f 0
nc 964
nop 1
dl 0
loc 96
rs 0.05

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
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2013 Jonathan Vollebregt ([email protected]), Rokas Šleinius ([email protected])
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
9
 * this software and associated documentation files (the "Software"), to deal in
10
 * the Software without restriction, including without limitation the rights to
11
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12
 * the Software, and to permit persons to whom the Software is furnished to do so,
13
 * subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in all
16
 * copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 */
25
26
namespace Kint\Renderer\Rich;
27
28
use Kint\Object\BlobObject;
29
use Kint\Object\Representation\Representation;
30
use Kint\Renderer\RichRenderer;
31
32
class TablePlugin extends Plugin implements TabPluginInterface
33
{
34
    public static $respect_str_length = true;
35
36
    public function renderTab(Representation $r)
37
    {
38
        $out = '<pre><table><thead><tr><th></th>';
39
40
        $firstrow = \reset($r->contents);
41
42
        foreach ($firstrow->value->contents as $field) {
43
            $out .= '<th>'.$this->renderer->escape($field->name).'</th>';
44
        }
45
46
        $out .= '</tr></thead><tbody>';
47
48
        foreach ($r->contents as $row) {
49
            $out .= '<tr><th>';
50
            $out .= $this->renderer->escape($row->name);
51
            $out .= '</th>';
52
53
            foreach ($row->value->contents as $field) {
54
                $out .= '<td';
55
                $type = '';
56
                $size = '';
57
                $ref = '';
58
59
                if (null !== ($s = $field->getType())) {
60
                    $type = $this->renderer->escape($s);
61
62
                    if ($field->reference) {
63
                        $ref = '&amp;';
64
                        $type = $ref.$type;
65
                    }
66
67
                    if (null !== ($s = $field->getSize())) {
68
                        $size .= ' ('.$this->renderer->escape($s).')';
69
                    }
70
                }
71
72
                if ($type) {
73
                    $out .= ' title="'.$type.$size.'"';
74
                }
75
76
                $out .= '>';
77
78
                switch ($field->type) {
79
                    case 'boolean':
80
                        $out .= $field->value->contents ? '<var>'.$ref.'true</var>' : '<var>'.$ref.'false</var>';
81
                        break;
82
                    case 'integer':
83
                    case 'double':
84
                        $out .= (string) $field->value->contents;
85
                        break;
86
                    case 'null':
87
                        $out .= '<var>'.$ref.'null</var>';
88
                        break;
89
                    case 'string':
90
                        if ($field->encoding) {
91
                            $val = $field->value->contents;
92
                            if (RichRenderer::$strlen_max && self::$respect_str_length && BlobObject::strlen($val) > RichRenderer::$strlen_max) {
93
                                $val = \substr($val, 0, RichRenderer::$strlen_max).'...';
94
                            }
95
96
                            $out .= $this->renderer->escape($val);
97
                        } else {
98
                            $out .= '<var>'.$type.'</var>';
99
                        }
100
                        break;
101
                    case 'array':
102
                        $out .= '<var>'.$ref.'array</var>'.$size;
103
                        break;
104
                    case 'object':
105
                        $out .= '<var>'.$ref.$this->renderer->escape($field->classname).'</var>'.$size;
106
                        break;
107
                    case 'resource':
108
                        $out .= '<var>'.$ref.'resource</var>';
109
                        break;
110
                    default:
111
                        $out .= '<var>'.$ref.'unknown</var>';
112
                        break;
113
                }
114
115
                if (\in_array('blacklist', $field->hints, true)) {
116
                    $out .= ' <var>Blacklisted</var>';
117
                } elseif (\in_array('recursion', $field->hints, true)) {
118
                    $out .= ' <var>Recursion</var>';
119
                } elseif (\in_array('depth_limit', $field->hints, true)) {
120
                    $out .= ' <var>Depth Limit</var>';
121
                }
122
123
                $out .= '</td>';
124
            }
125
126
            $out .= '</tr>';
127
        }
128
129
        $out .= '</tbody></table></pre>';
130
131
        return $out;
132
    }
133
}
134