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

Heading   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 12
c 4
b 0
f 2
lcom 1
cbo 0
dl 0
loc 85
ccs 34
cts 34
cp 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getNumber() 0 4 1
A getTitle() 0 4 1
A getId() 0 4 1
A getHref() 0 8 2
A getHrefAnchor() 0 9 2
A getAnchor() 0 9 2
A getLevel() 0 4 1
A asArray() 0 4 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