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

Commit   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 113
Duplicated Lines 7.08 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 91.8%

Importance

Changes 6
Bugs 0 Features 1
Metric Value
wmc 24
c 6
b 0
f 1
lcom 1
cbo 0
dl 8
loc 113
ccs 56
cts 61
cp 0.918
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A set() 0 6 1
A setHash() 0 4 1
A getHash() 0 4 1
A setLabel() 0 11 3
A getLabel() 0 7 4
A addComment() 0 4 1
A addComments() 0 6 2
A setComments() 0 5 1
A getComments() 0 4 1
A setDate() 8 8 2
A getDate() 0 4 2
A setSubject() 0 5 1
A getSubject() 0 4 1
A setAuthor() 0 5 1
A getAuthor() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
 * Commit class.
16
 * Holds commit properties:
17
 * - hash
18
 * - date
19
 * - author
20
 * - subject
21
 * - list of comments.
22
 *
23
 * @author Andrii Vasyliev <[email protected]>
24
 */
25
class Commit
26
{
27
    protected $_hash;
28
    protected $_label;
29
    protected $_comments = [];
30
31
    protected $_date;
32
    protected $_author;
33
    protected $_subject;
34
35 2
    public function __construct($hash, $label = null, array $comments = [])
36
    {
37 2
        $this->setHash($hash);
38 2
        $this->setLabel($label);
39 2
        $this->setComments($comments);
40 2
    }
41
42
    public function set(Commit $commit)
43
    {
44
        $this->setHash($commit->hashHash());
0 ignored issues
show
Bug introduced by
The method hashHash() does not seem to exist on object<hiqdev\chkipper\history\Commit>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
        $this->setLabel($commit->getLabel());
46
        $this->setComments($commit->getComments());
47
    }
48
49 2
    public function setHash($hash)
50
    {
51 2
        $this->_hash = $hash;
52 2
    }
53
54 1
    public function getHash()
55
    {
56 1
        return $this->_hash;
57
    }
58
59 2
    public function setLabel($label)
60
    {
61 2
        if ($label) {
62 2
            $this->_label = $label;
63 2
            if (preg_match('/^(\d{4}-\d{2}-\d{2})\s*(.*?)\s*[\(\[](.*?)[\)\]]$/', $label, $m)) {
64 2
                $this->setDate($m[1]);
65 2
                $this->setSubject($m[2]);
66 2
                $this->setAuthor($m[3]);
67 2
            }
68 2
        }
69 2
    }
70
71 1
    public function getLabel()
72
    {
73 1
        return $this->_subject || $this->_date || $this->_author
74 1
            ? $this->getDate() . ' ' . $this->getSubject() . ' [' . $this->getAuthor() . ']'
75 1
            : $this->_label
76 1
        ;
77
    }
78
79 2
    public function addComment($comment)
80
    {
81 2
        $this->_comments[$comment] = $comment;
82 2
    }
83
84 2
    public function addComments(array $comments)
85
    {
86 2
        foreach ($comments as $comment) {
87 1
            $this->addComment($comment);
88 2
        }
89 2
    }
90
91 2
    public function setComments($comments)
92
    {
93 2
        $this->_comments = [];
94 2
        $this->addComments($comments);
95 2
    }
96
97 1
    public function getComments()
98
    {
99 1
        return $this->_comments;
100
    }
101
102 2 View Code Duplication
    public function setDate($value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
    {
104 2
        $timestamp = strtotime($value);
105 2
        if ($timestamp !== false) {
106 2
            $this->_date = $timestamp;
107 2
        }
108
        return $this;
109 2
    }
110
111
    public function getDate()
112 1
    {
113
        return $this->_date ? date('Y-m-d', $this->_date) : null;
114 1
    }
115
116
    public function setSubject($value)
117 2
    {
118
        $this->_subject = $value;
119 2
        return $this;
120
    }
121 2
122
    public function getSubject()
123
    {
124 1
        return $this->_subject;
125
    }
126 1
127
    public function setAuthor($value)
128
    {
129 2
        $this->_author = $value;
130
        return $this;
131 2
    }
132
133 2
    public function getAuthor()
134
    {
135
        return $this->_author;
136 1
    }
137
}
138