Passed
Push — master ( 08368b...d03553 )
by Sebastian
02:27
created

VariableInfo_Renderer_HTML   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 24
c 1
b 0
f 0
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 2 1
A getTypeColor() 0 3 1
A render() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AppUtils;
6
7
abstract class VariableInfo_Renderer_HTML extends VariableInfo_Renderer
8
{
9
    protected static $colors = array(
10
        self::TYPE_DOUBLE => 'ce0237',
11
        self::TYPE_INTEGER => 'ce0237',
12
        self::TYPE_ARRAY => '027ace',
13
        self::TYPE_OBJECT => 'cf5e20',
14
        self::TYPE_RESOURCE => '1c2eb1',
15
        self::TYPE_STRING => '1fa507',
16
        self::TYPE_BOOLEAN => '1c2eb1',
17
        self::TYPE_NULL => '1c2eb1',
18
        self::TYPE_UNKNOWN => 'cc0000',
19
        self::TYPE_CALLABLE => 'cf5e20'
20
    );
21
    
22
    protected function init()
23
    {
24
        
25
    }
26
    
27
    public function getTypeColor() : string
28
    {
29
        return self::$colors[$this->type];
30
    }
31
    
32
    public function render()
33
    {
34
        $converted = sprintf(
35
            '<span style="color:#%1$s" class="variable-value-%3$s">'.
36
                '%2$s'.
37
            '</span>',
38
            $this->getTypeColor(),
39
            $this->_render(),
40
            str_replace(' ', '-', $this->type)
41
        );
42
        
43
        if($this->info->getBoolOption('prepend-type') && !$this->info->isNull())
44
        {
45
            $typeLabel = '<span style="color:#1c2eb1" class="variable-type">'.$this->info->getType().'</span> ';
46
            $converted = $typeLabel.' '.$converted;
47
        }
48
        
49
        return $converted;
50
    }
51
}
52