Completed
Push — master ( fdef12...11a376 )
by Andrii
02:13
created

Note::removeCommit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
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-2017, 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 3
    public function __construct($note, $commits = [])
34
    {
35 3
        $this->_note    = $note;
36 3
        $this->_commits = $commits;
37 3
    }
38
39 3
    public function findCommit($hash)
40
    {
41 3
        if (!isset($this->_commits[$hash])) {
42 3
            $this->_commits[$hash] = new Commit($hash);
43 3
        }
44
45 3
        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 1
    public function addCommit(Commit $commit)
65
    {
66 1
        $new = $this->findCommit($commit->getHash());
67 1
        $new->setLabel($commit->getLabel());
68 1
        $new->addComments($commit->getComments());
69 1
    }
70
71
    /**
72
     * Appends commits along with comments.
73
     * @param Commit[] array of commits
74
     */
75 1
    public function addCommits(array $commits)
76
    {
77 1
        foreach ($commits as $commit) {
78 1
            $this->addCommit($commit);
79 1
        }
80 1
    }
81
82
    /**
83
     * Returns commits.
84
     * @return Commit[]
85
     */
86 3
    public function getCommits()
87
    {
88 3
        return $this->_commits;
89
    }
90
91
    public function setNote($value)
92
    {
93
        $this->_note = $value;
94
    }
95
96 3
    public function getNote()
97
    {
98 3
        return $this->_note;
99
    }
100
}
101