Format::begin()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
crap 1
1
<?php
2
3
namespace BestServedCold\HTMLBuilder\Output;
4
5
use BestServedCold\HTMLBuilder\Html\Node;
6
7
/**
8
 * Class Format
9
 *
10
 * @package BestServedCold\HTMLBuilder\Output
11
 */
12
abstract class Format
13
{
14
    /**
15
     * @var int $tabSize
16
     */
17
    private static $tabSize = 4;
18
19
    /**
20
     * @param  string $string
21
     * @param  int    $depth
22
     * @return string
23
     */
24 3
    public static function string($string, $depth)
25
    {
26 3
        return str_pad($string, strlen($string) + ($depth * self::$tabSize), ' ', STR_PAD_LEFT) . PHP_EOL;
27
    }
28
29
    /**
30
     * @param int $tabSize
31
     */
32 1
    public static function setTabSize($tabSize)
33
    {
34 1
        self::$tabSize = $tabSize;
35 1
    }
36
37
    /**
38
     * @param  Node   $node
39
     * @param  string $attributes
40
     * @param  int    $depth
41
     * @return string
42
     */
43 3
    public static function begin(Node $node, $attributes, $depth)
44
    {
45 3
        return self::string('<' . $node->getType()  . $attributes . '>', $depth);
46
    }
47
48
    /**
49
     * @param  Node   $node
50
     * @param  int    $depth
51
     * @return string
52
     */
53 3
    public static function end(Node $node, $depth)
54
    {
55 3
        return self::string('</' . $node->getType() . '>', $depth);
56
    }
57
}
58