Test Setup Failed
Push — test ( 528f91...abcbcc )
by Jonathan
03:20
created

ColorPlugin::renderTab()   F

Complexity

Conditions 13
Paths 321

Size

Total Lines 46
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 27
nc 321
nop 1
dl 0
loc 46
rs 3.7737
c 0
b 0
f 0

How to fix   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
namespace Kint\Renderer\Rich;
4
5
use Kint\Object\BasicObject;
6
use Kint\Object\ColorObject;
7
use Kint\Object\Representation\ColorRepresentation;
8
use Kint\Object\Representation\Representation;
9
10
class ColorPlugin extends Plugin implements TabPluginInterface, ObjectPluginInterface
11
{
12
    public function renderObject(BasicObject $o)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
13
    {
14
        if (!$o instanceof ColorObject) {
15
            return;
16
        }
17
18
        $children = $this->renderer->renderChildren($o);
19
20
        $header = $this->renderer->renderHeader($o);
21
        $header .= '<div class="kint-color-preview"><div style="background:';
22
        $header .= $o->color->getColor(ColorRepresentation::COLOR_RGBA);
23
        $header .= '"></div></div>';
24
25
        $header = $this->renderer->renderHeaderWrapper($o, (bool) strlen($children), $header);
26
27
        return '<dl>'.$header.$children.'</dl>';
28
    }
29
30
    public function renderTab(Representation $r)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $r. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
31
    {
32
        if (!$r instanceof ColorRepresentation) {
33
            return false;
34
        }
35
36
        $out = '';
37
38
        if ($color = $r->getColor(ColorRepresentation::COLOR_NAME)) {
39
            $out .= '<dfn>'.$color."</dfn>\n";
40
        }
41
        if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_3)) {
42
            $out .= '<dfn>'.$color."</dfn>\n";
43
        }
44
        if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_6)) {
45
            $out .= '<dfn>'.$color."</dfn>\n";
46
        }
47
48
        if ($r->hasAlpha()) {
49
            if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_4)) {
50
                $out .= '<dfn>'.$color."</dfn>\n";
51
            }
52
            if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_8)) {
53
                $out .= '<dfn>'.$color."</dfn>\n";
54
            }
55
            if ($color = $r->getColor(ColorRepresentation::COLOR_RGBA)) {
56
                $out .= '<dfn>'.$color."</dfn>\n";
57
            }
58
            if ($color = $r->getColor(ColorRepresentation::COLOR_HSLA)) {
59
                $out .= '<dfn>'.$color."</dfn>\n";
60
            }
61
        } else {
62
            if ($color = $r->getColor(ColorRepresentation::COLOR_RGB)) {
63
                $out .= '<dfn>'.$color."</dfn>\n";
64
            }
65
            if ($color = $r->getColor(ColorRepresentation::COLOR_HSL)) {
66
                $out .= '<dfn>'.$color."</dfn>\n";
67
            }
68
        }
69
70
        if (!strlen($out)) {
71
            return false;
72
        }
73
74
        return '<pre>'.$out.'</pre>';
75
    }
76
}
77