ElementAbstract::getTabulationFormatted()   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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the ClassGeneration package.
5
 *
6
 * (c) Antonio Spinelli <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ClassGeneration\Element;
13
14
/**
15
 * Abstract ClassGeneration
16
 * @author Antonio Spinelli <[email protected]>
17
 */
18
abstract class ElementAbstract implements ElementInterface, Tabbable
19
{
20
21
    /**
22
     * Tabulation Identity.
23
     * @var int
24
     */
25
    protected $tabulation = 4;
26
27
    /**
28
     * Parent Class.
29
     * @var ElementInterface
30
     */
31
    protected $parent = null;
32
33
    /**
34
     * @{inheritdoc}
35
     */
36
    abstract public function init();
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    abstract public function toString();
42
43 142
    public function __construct($options = array())
44
    {
45 142
        $this->init();
46 142
        $this->setOptions($options);
47 142
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 2
    public function getParent()
53
    {
54 2
        return $this->parent;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 36
    public function setParent(ElementInterface $parent)
61
    {
62 36
        $this->parent = $parent;
63
64 36
        return $this;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 142
    public function setOptions(array $options)
71
    {
72 142
        foreach ($options as $prop => $option) {
73 76
            $method = 'set' . ucfirst($prop);
74 76
            if (method_exists($this, $method)) {
75 76
                $this->$method($option);
76 76
            }
77 142
        }
78
79 142
        return $this;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85 29
    public function getTabulation()
86
    {
87 29
        return $this->tabulation;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93 26
    public function getTabulationFormatted()
94
    {
95 26
        return str_repeat(' ', $this->getTabulation());
96
    }
97
98
    /**
99
     * @inheritdoc
100
     */
101 46
    public function setTabulation($tabulation)
102
    {
103 46
        $this->tabulation = (int)$tabulation;
104
105 46
        return $this;
106
    }
107
}
108