Completed
Push — master ( 6b97aa...4718f0 )
by Sebastian
03:20
created

GetMostRecentTag   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 10
c 1
b 0
f 0
dl 0
loc 66
ccs 12
cts 12
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A before() 0 5 1
A startingPoint() 0 3 2
A ignore() 0 4 1
A tagsToIgnore() 0 3 2
A getGitCommand() 0 3 1
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\Describe;
11
12
use SebastianFeldmann\Git\Command\Base;
13
14
/**
15
 * Class GetCurrentTag
16
 *
17
 * @package SebastianFeldmann\Git
18
 * @author  Sebastian Feldmann <[email protected]>
19
 * @link    https://github.com/sebastianfeldmann/git
20
 * @since   Class available since Release 1.0.8
21
 */
22
class GetMostRecentTag extends Base
23
{
24
    /**
25
     * @var string
26
     */
27
    private $before;
28
29
    /**
30
     * Glob to define excluded tags e.g **-RC* to exclude release candidate tags
31
     * @var string
32
     */
33
    private $exclude;
34
35
    /**
36
     * Sets the start point to search for a tag
37
     *
38
     * @param  string $hash
39
     * @return \SebastianFeldmann\Git\Command\Describe\GetMostRecentTag
40
     */
41 2
    public function before(string $hash): GetMostRecentTag
42
    {
43 2
        $this->before = $hash;
44
45 2
        return $this;
46
    }
47
48
    /**
49
     * Glob of tags to ignore e.g. **-RC* to ignore release candidate tags like '1.0.0-RC3'
50
     *
51
     * @param  string $glob
52
     * @return \SebastianFeldmann\Git\Command\Describe\GetMostRecentTag
53
     */
54 3
    public function ignore(string $glob): GetMostRecentTag
55
    {
56 3
        $this->exclude = $glob;
57 3
        return $this;
58
    }
59
60
    /**
61
     * Return the command to execute.
62
     *
63
     * @return string
64
     */
65 3
    protected function getGitCommand(): string
66
    {
67 3
        return 'describe --tags --abbrev=0' . $this->tagsToIgnore() . $this->startingPoint();
68
    }
69
70
    /**
71
     * Return the --exclude='xxx' option
72
     *
73
     * @return string
74
     */
75 3
    private function tagsToIgnore(): string
76
    {
77 3
        return empty($this->exclude) ? '' : ' --exclude=' . escapeshellarg($this->exclude);
78
    }
79
80
    /**
81
     * Return the starting point where to start the search for a tag
82
     *
83
     * @return string
84
     */
85 3
    private function startingPoint(): string
86
    {
87 3
        return empty($this->before) ? '' : ' ' . $this->before . '^';
88
    }
89
}
90