Completed
Push — master ( 4dab06...9e5ffc )
by Andrii
03:02
created

Note::addCommit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
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
 * Note class.
16
 *
17
 * @property string $note
18
 * @property Commit[] $commits
19
 *
20
 * @author Andrii Vasyliev <[email protected]>
21
 */
22
class Note
23
{
24
    /**
25
     * @var string note
26
     */
27
    protected $_note;
28
29
    /**
30
     * @var Commit[] array of commits
31
     */
32
    protected $_commits = [];
33
34 3
    public function __construct($note, $commits = [])
35
    {
36 3
        $this->_note    = $note;
37 3
        $this->_commits = $commits;
38 3
    }
39
40 3
    public function findCommit($hash)
41
    {
42 3
        if (!isset($this->_commits[$hash])) {
43 3
            $this->_commits[$hash] = new Commit($hash);
44 3
        }
45
46 3
        return $this->_commits[$hash];
47
    }
48
49
    /**
50
     * Appends commit along with comments.
51
     * @param Commit commit object
52
     */
53 1
    public function addCommit(Commit $commit)
54
    {
55 1
        $new = $this->findCommit($commit->getHash());
56 1
        $new->setLabel($commit->getLabel());
57 1
        $new->addComments($commit->getComments());
58 1
    }
59
60
    /**
61
     * Appends commits along with comments.
62
     * @param Commit[] array of commits
63
     */
64 1
    public function addCommits(array $commits)
65
    {
66 1
        foreach ($commits as $commit) {
67 1
            $this->addCommit($commit);
68 1
        }
69 1
    }
70
71
    /**
72
     * Returns commits.
73
     * @return Commit[]
74
     */
75 3
    public function getCommits()
76
    {
77 3
        return $this->_commits;
78
    }
79
80
    public function setNote($value)
81
    {
82
        $this->_note = $value;
83
    }
84
85 3
    public function getNote()
86
    {
87 3
        return $this->_note;
88
    }
89
}
90