Completed
Push — master ( 808823...246322 )
by Andrii
02:33
created

Builder::addCommit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * Changelog keeper
5
 *
6
 * @link      https://github.com/hiqdev/chkipper
7
 * @package   chkipper
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\chkipper\history;
13
14
/**
15
 * Builder class.
16
 *
17
 * @author Andrii Vasyliev <[email protected]>
18
 */
19
class Builder
20
{
21
    /**
22
     * @var string current tag
23
     */
24
    protected $_tag = '';
25
26
    /**
27
     * @var string current note
28
     */
29
    protected $_note = '';
30
31
    /**
32
     * @var string current commit's hash
33
     */
34
    protected $_hash = '';
35
36
    /**
37
     * @var History history object
38
     */
39
    protected $_history;
40
41
    public function setHistory($history)
42
    {
43
        $this->_history = $history;
44
    }
45
46 2
    public function getHistory()
47
    {
48 2
        if ($this->_history === null) {
49 2
            $this->_history = new History();
50 2
        }
51
52 2
        return $this->_history;
53
    }
54
55 2
    public function setTag($tag)
56
    {
57 2
        $this->_tag  = $tag;
58 2
        $this->setNote('');
59 2
    }
60
61 2
    public function setNote($note)
62
    {
63 2
        $this->_note = $note;
64 2
        $this->setHash('');
65 2
    }
66
67 2
    public function setHash($hash)
68
    {
69 2
        $this->_hash = (string) $hash;
70 2
    }
71
72 2
    public function getTag()
73
    {
74 2
        return $this->_tag;
75
    }
76
77 2
    public function getNote()
78
    {
79 2
        return $this->_note;
80
    }
81
82 2
    public function getHash()
83
    {
84 2
        return $this->_hash;
85
    }
86
87 2
    public function addHeader($header)
88
    {
89 2
        $this->getHistory()->addHeader($header);
90 2
    }
91
92 2
    public function addTag($tag, $date = null)
93
    {
94 2
        $this->setTag($tag);
95 2
        $this->getHistory()->addTag($tag, $date);
96 2
    }
97
98 2
    public function addNote($note)
99
    {
100 2
        $this->setNote($note);
101 2
        $this->getHistory()->findNote($this->getTag(), $note);
102 2
    }
103
104 2
    public function addCommit($hash, $label)
105
    {
106 2
        $this->setHash($hash);
107 2
        $this->getHistory()->findCommit($this->getTag(), $this->getNote(), $hash)->setLabel($label);
108 2
    }
109
110 2
    public function addComment($comment)
111
    {
112 2
        $this->getHistory()->findCommit($this->getTag(), $this->getNote(), $this->getHash())->addComment($comment);
113 2
    }
114
115 2
    public function addLink($link, $href)
116
    {
117 2
        $this->getHistory()->addLink($link, $href);
118 2
    }
119
120 1
    public function getLastTag()
121
    {
122 1
        return $this->getHistory()->lastTag;
123
    }
124
125 1
    public function getInitTag()
126
    {
127 1
        return $this->getHistory()->initTag;
128
    }
129
}
130