Output::setDepth()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace BestServedCold\HTMLBuilder;
4
5
use BestServedCold\HTMLBuilder\Html\Node;
6
use BestServedCold\HTMLBuilder\Output\Format;
7
use BestServedCold\PhalueObjects\ExtendedArray\ExtendedArrayTrait;
8
use BestServedCold\HTMLBuilder\Output\Children;
9
10
/**
11
 * Class Output
12
 * 
13
 * @package BestServedCold\HTMLBuilder
14
 */
15
class Output
16
{
17
    use ExtendedArrayTrait;
18
19
    /**
20
     * @var Node
21
     */
22
    private $node;
23
24
    /**
25
     * @var int
26
     */
27
    private $depth = 0;
28
29
    /**
30
     * @var int
31
     */
32
    private static $initialDepth = 0;
33
34
    /**
35
     * Output constructor.
36
     *
37
     * @param Node $node
38
     * @param int  $depth
39
     */
40 4
    public function __construct(Node $node, $depth = null)
41
    {
42 4
        $this->node  = $node;
43 4
        $this->depth = $depth ? $depth : self::$initialDepth;
44 4
    }
45
46
    /**
47
     * @param int $depth
48
     */
49 3
    public static function setDepth($depth)
50
    {
51 3
        self::$initialDepth = $depth;
52 3
    }
53
54
    /**
55
     * @return string
56
     */
57 3
    public function get()
58
    {
59 3
        $begin = Format::begin($this->node, $this->attributes(), $this->depth);
60 3
        return $this->node->isVoid()
61 3
            ? $begin
62 3
            : $begin . Children::run($this->node, $this->depth) . Format::end($this->node, $this->depth);
63
    }
64
65
    /**
66
     * 
67
     */
68 1
    public function render()
69
    {
70 1
        echo $this->get();
71 1
    }
72
73
    /**
74
     * @param int $tabSize
75
     */
76 1
    public static function setTabSize($tabSize)
77
    {
78 1
        Format::setTabSize($tabSize);
79 1
    }
80
81
    /**
82
     * @param  string      $string
83
     * @return null|string
84
     */
85 3
    private function attributes($string = ' ')
86
    {
87 3
        return empty($this->node->getAttributes())
88 3
            ? null
89 3
            : $string . $this->arrayToAttributeArray($this->node->getAttributes());
90
    }
91
}
92