Completed
Push — master ( 3952c5...023801 )
by Sebastian
02:12
created

Log   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 5
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 5
cbo 1
dl 0
loc 121
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A prettyFormat() 0 5 1
A withMerges() 0 5 2
A abbrevCommit() 0 5 2
A byRevision() 0 6 2
A authoredBy() 0 5 1
A byDate() 0 6 2
1
<?php
2
/**
3
 * This file is part of SebastianFeldmann\Git.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianFeldmann\Git\Command\Log;
11
12
use SebastianFeldmann\Git\Command\Base;
13
14
/**
15
 * Class Log
16
 *
17
 * @package SebastianFeldmann\Git
18
 */
19
abstract class Log extends Base
20
{
21
    /**
22
     * Pretty log format.
23
     * --pretty
24
     *
25
     * @var string
26
     */
27
    protected $format = '%h -%d %s (%ci) <%an>';
28
29
    /**
30
     * Include or hide merge commits.
31
     * --no-merges
32
     *
33
     * @var string
34
     */
35
    protected $merges = ' --no-merges';
36
37
    /**
38
     * Shorten commit hashes.
39
     * --abbrev-commit
40
     *
41
     * @var bool
42
     */
43
    protected $abbrev = ' --abbrev-commit';
44
45
    /**
46
     * Can be revision or date query.
47
     *  1.0.0..
48
     *  0.9.0..1.2.0
49
     *  --after='2016-12-31'
50
     *  --after='2016-12-31' --before='2017-01-31'
51
     *
52
     * @var string
53
     */
54
    protected $since;
55
56
    /**
57
     * Filter log by author.
58
     * --author
59
     *
60
     * @var string
61
     */
62
    protected $author;
63
64
    /**
65
     * Define the pretty log format.
66
     *
67
     * @param  string $format
68
     * @return \SebastianFeldmann\Git\Command\Log\Log
69
     */
70 2
    public function prettyFormat(string $format) : Log
71
    {
72 2
        $this->format = $format;
73 2
        return $this;
74
    }
75
76
    /**
77
     * Define merge commit behaviour.
78
     *
79
     * @param  bool $bool
80
     * @return \SebastianFeldmann\Git\Command\Log\Log
81
     */
82 1
    public function withMerges(bool $bool = true) : Log
83
    {
84 1
        $this->merges = ($bool ? '' : ' --no-merges');
85 1
        return $this;
86
    }
87
88
    /**
89
     * Define commit hash behaviour.
90
     *
91
     * @param  bool $bool
92
     * @return \SebastianFeldmann\Git\Command\Log\Log
93
     */
94 1
    public function abbrevCommit(bool $bool = true) : Log
95
    {
96 1
        $this->abbrev = ($bool ? ' --abbrev--commit' : '');
0 ignored issues
show
Documentation Bug introduced by
The property $abbrev was declared of type boolean, but $bool ? ' --abbrev--commit' : '' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
97 1
        return $this;
98
    }
99
100
    /**
101
     * Set revision range.
102
     *
103
     * @param  string $from
104
     * @param  string $to
105
     * @return \SebastianFeldmann\Git\Command\Log\Log
106
     */
107 4
    public function byRevision(string $from, string $to = '') : Log
108
    {
109 4
        $this->since = ' ' . escapeshellarg($from) . '..'
110 4
                     . (empty($to) ? '' : escapeshellarg($to));
111 4
        return $this;
112
    }
113
114
    /**
115
     * Set author filter.
116
     *
117
     * @param  string $author
118
     * @return \SebastianFeldmann\Git\Command\Log\Log
119
     */
120 1
    public function authoredBy(string $author) : Log
121
    {
122 1
        $this->author = ' --author=' . escapeshellarg($author);
123 1
        return $this;
124
    }
125
126
    /**
127
     * Set date range.
128
     *
129
     * @param  string $from
130
     * @param  string $to
131
     * @return \SebastianFeldmann\Git\Command\Log\Log
132
     */
133 2
    public function byDate(string $from, string $to = '') : Log
134
    {
135 2
        $this->since = ' --after=' . escapeshellarg($from)
136 2
                     . (empty($to) ? '' : ' --before=' . escapeshellarg($to));
137 2
        return $this;
138
    }
139
}
140