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

VariableInfo_Renderer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A cutString() 0 5 1
A render() 0 3 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AppUtils;
6
7
abstract class VariableInfo_Renderer
8
{
9
   /**
10
    * @var mixed
11
    */
12
    protected $value;
13
    
14
   /**
15
    * @var VariableInfo
16
    */
17
    protected $info;
18
    
19
   /**
20
    * @var string
21
    */
22
    protected $type;
23
    
24
    public function __construct(VariableInfo $info)
25
    {
26
        $this->info = $info;
27
        $this->type = $info->getType();
28
        
29
        $this->init();
30
    }
31
    
32
    abstract protected function init();
33
34
   /**
35
    * Renders the value to the target format.
36
    * 
37
    * @return mixed
38
    */
39
    public function render()
40
    {
41
        return $this->_render();
42
    }
43
    
44
    abstract protected function _render();
45
46
    protected function cutString(string $string) : string
47
    {
48
        $cutAt = $this->info->getIntOption('cut-length', 1000);
49
        
50
        return ConvertHelper::text_cut($string, $cutAt, ' [...]');
51
    }
52
}
53