Completed
Push — master ( 69f712...a96098 )
by Andrii
02:39
created

Note   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 67.65%

Importance

Changes 5
Bugs 0 Features 3
Metric Value
wmc 12
c 5
b 0
f 3
lcom 1
cbo 1
dl 0
loc 80
ccs 23
cts 34
cp 0.6765
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A findCommit() 0 8 2
A removeCommit() 0 4 1
A removeCommits() 0 6 2
A addCommit() 0 6 1
A addCommits() 0 6 2
A getCommits() 0 4 1
A setNote() 0 4 1
A getNote() 0 4 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
    public function removeCommit($hash)
50
    {
51
        unset($this->_commits[$hash]);
52
    }
53
54
    public function removeCommits($hashes)
55
    {
56
        foreach ($hashes as $hash) {
57
            $this->removeCommit($hash);
58
        }
59
    }
60
61
    /**
62
     * Appends commit along with comments.
63
     * @param Commit commit object
64
     */
65 1
    public function addCommit(Commit $commit)
66
    {
67 1
        $new = $this->findCommit($commit->getHash());
68 1
        $new->setLabel($commit->getLabel());
69 1
        $new->addComments($commit->getComments());
70 1
    }
71
72
    /**
73
     * Appends commits along with comments.
74
     * @param Commit[] array of commits
75
     */
76 1
    public function addCommits(array $commits)
77
    {
78 1
        foreach ($commits as $commit) {
79 1
            $this->addCommit($commit);
80 1
        }
81 1
    }
82
83
    /**
84
     * Returns commits.
85
     * @return Commit[]
86
     */
87 3
    public function getCommits()
88
    {
89 3
        return $this->_commits;
90
    }
91
92
    public function setNote($value)
93
    {
94
        $this->_note = $value;
95
    }
96
97 3
    public function getNote()
98
    {
99 3
        return $this->_note;
100
    }
101
}
102