Completed
Push — master ( 7b4929...cefe8d )
by Andrii
01:50
created

Note::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * Changelog keeper
4
 *
5
 * @link      https://github.com/hiqdev/chkipper
6
 * @package   chkipper
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\chkipper\history;
12
13
/**
14
 * Note class.
15
 *
16
 * @property string $note
17
 * @property Commit[] $commits
18
 *
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class Note
22
{
23
    /**
24
     * @var string note
25
     */
26
    protected $_note;
27
28
    /**
29
     * @var Commit[] array of commits
30
     */
31
    protected $_commits = [];
32
33
    public function __construct($note, $commits = [])
34
    {
35
        $this->_note    = $note;
36
        $this->_commits = $commits;
37
    }
38
39
    public function findCommit($hash)
40
    {
41
        if (!isset($this->_commits[$hash])) {
42
            $this->_commits[$hash] = new Commit($hash);
43
        }
44
45
        return $this->_commits[$hash];
46
    }
47
48
    public function removeCommit($hash)
49
    {
50
        unset($this->_commits[$hash]);
51
    }
52
53
    public function removeCommits($hashes)
54
    {
55
        foreach ($hashes as $hash) {
56
            $this->removeCommit($hash);
57
        }
58
    }
59
60
    /**
61
     * Appends commit along with comments.
62
     * @param Commit commit object
63
     */
64
    public function addCommit(Commit $commit)
65
    {
66
        $new = $this->findCommit($commit->getHash());
67
        $new->setLabel($commit->getLabel());
68
        $new->addComments($commit->getComments());
69
    }
70
71
    /**
72
     * Appends commits along with comments.
73
     * @param Commit[] array of commits
74
     */
75
    public function addCommits(array $commits)
76
    {
77
        foreach ($commits as $commit) {
78
            $this->addCommit($commit);
79
        }
80
    }
81
82
    /**
83
     * Returns commits.
84
     * @return Commit[]
85
     */
86
    public function getCommits()
87
    {
88
        return $this->_commits;
89
    }
90
91
    public function setNote($value)
92
    {
93
        $this->_note = $value;
94
    }
95
96
    public function getNote()
97
    {
98
        return $this->_note;
99
    }
100
}
101