Completed
Pull Request — master (#2)
by Adam
01:53
created

Output::attributes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 1
cts 1
cp 1
cc 2
eloc 4
nc 2
nop 1
crap 2
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 static $depth = 0;
28
29
    /**
30
     * Output constructor.
31
     *
32 2
     * @param Node $node
33
     * @param int  $depth
34 2
     */
35 2
    public function __construct(Node $node, $depth = null)
36 2
    {
37
        $this->node  = $node;
38
        $depth ? self::$depth = $depth : null;
39
    }
40
41 2
    /**
42
     * @param int $depth
43 2
     */
44 2
    public static function setDepth($depth)
45 2
    {
46 2
        self::$depth = $depth;
47 2
    }
48 2
49
    /**
50
     * @return string
51
     */
52
    public function get()
53
    {
54 1
        $begin = Format::begin($this->node, $this->attributes(), self::$depth);
55
        return $this->node->isVoid()
56 1
            ? $begin
57 1
            : $begin . Children::run($this->node, self::$depth) . Format::end($this->node, self::$depth);
58
    }
59
60
    /**
61
     * @param int $tabSize
62
     */
63 2
    public static function setTabSize($tabSize)
64
    {
65
        Format::setTabSize($tabSize);
66 2
    }
67 1
68 2
    /**
69
     * @param  string      $string
70 2
     * @return null|string
71
     */
72
    private function attributes($string = ' ')
73
    {
74
        return empty($this->node->getAttributes())
75
            ? null
76
            : $string . $this->arrayToAttributeArray($this->node->getAttributes());
77 1
    }
78
}
79