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

ColorPlugin   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 15
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A renderObject() 0 17 2
F renderTab() 0 46 13
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