Completed
Push — master ( bcbde7...9c8e56 )
by Paul
03:11
created

Heading::getId()   A

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
namespace Bookdown\Bookdown\Content;
3
4
class Heading
5
{
6
    protected $number;
7
8
    protected $title;
9
10
    protected $id;
11
12
    protected $href;
13
14
    protected $level;
15
16 15
    public function __construct($number, $title, $href, $id = null)
17
    {
18 15
        $this->number = $number;
19 15
        $this->title = $title;
20 15
        $this->href = $href;
21 15
        $this->id = $id;
22 15
        $this->level = substr_count($number, '.');
23 15
    }
24
25 14
    public function getNumber()
26
    {
27 14
        return $this->number;
28
    }
29
30 4
    public function getTitle()
31
    {
32 4
        return $this->title;
33
    }
34
35 14
    public function getId()
36
    {
37 14
        return $this->id;
38
    }
39
40 4
    public function getHref()
41
    {
42 4
        $href = $this->href;
43 4
        if ($this->id) {
44 3
            $href .= $this->getHrefAnchor();
45 3
        }
46 4
        return $href;
47
    }
48
49
    /**
50
     * Creates a complete anchor href attribute for links.
51
     *
52
     * @return string
53
     */
54 4
    public function getHrefAnchor()
55
    {
56 4
        $hrefAnchor = null;
57
58 4
        if ($this->id) {
59 3
            return '#' . $this->getAnchor();
60
        }
61 1
        return $hrefAnchor;
62
    }
63
64
    /**
65
     * Return a valid anchor string tag to use as html id attribute.
66
     *
67
     * @return string
68
     */
69 14
    public function getAnchor()
70
    {
71 14
        $anchor = null;
72
73 14
        if ($this->id) {
74 13
            $anchor = str_replace('.', '-', $this->getId());
75 13
        }
76 14
        return $anchor;
77
    }
78
79 10
    public function getLevel()
80
    {
81 10
        return $this->level;
82
    }
83
84 10
    public function asArray()
85
    {
86 10
        return get_object_vars($this);
87
    }
88
}
89