Passed
Push — master ( 6e3bd3...d52744 )
by Sebastian
02:51
created

Info::getCurrentBranch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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\Operator;
11
12
use SebastianFeldmann\Git\Command\Describe\GetCurrentTag;
13
use SebastianFeldmann\Git\Command\RevParse\GetBranch;
14
use SebastianFeldmann\Git\Command\RevParse\GetCommitHash;
15
use SebastianFeldmann\Git\Command\Tag\GetTags;
16
17
/**
18
 * Class Info
19
 *
20
 * @package SebastianFeldmann\Git
21
 * @author  Sebastian Feldmann <[email protected]>
22
 * @link    https://github.com/sebastianfeldmann/git
23
 * @since   Class available since Release 1.0.8
24
 */
25
class Info extends Base
26
{
27
    /**
28
     * Returns the tag of the current commit
29
     *
30
     * @return string
31
     */
32 2
    public function getCurrentTag() : string
33
    {
34 2
        $cmd    = new GetCurrentTag($this->repo->getRoot());
35 2
        $result = $this->runner->run($cmd);
36
37 1
        return trim($result->getStdOut());
38
    }
39
40
    /**
41
     * Returns a list of tags for a given commit hash
42
     *
43
     * @param  string $hash
44
     * @return string[]
45
     */
46 1
    public function getTagsPointingTo(string $hash): array
47
    {
48 1
        $cmd = new GetTags($this->repo->getRoot());
49 1
        $cmd->pointingTo($hash);
50
51 1
        $result = $this->runner->run($cmd);
52
53 1
        return $result->getBufferedOutput();
54
    }
55
56
    /**
57
     * Returns the the hash of the current commit
58
     *
59
     * @return string
60
     */
61 1
    public function getCurrentCommitHash() : string
62
    {
63 1
        $cmd    = new GetCommitHash($this->repo->getRoot());
64 1
        $result = $this->runner->run($cmd);
65
66 1
        return trim($result->getStdOut());
67
    }
68
69
    /**
70
     * Returns the current branch name
71
     *
72
     * @return string
73
     */
74 1
    public function getCurrentBranch() : string
75
    {
76 1
        $cmd    = new GetBranch($this->repo->getRoot());
77 1
        $result = $this->runner->run($cmd);
78
79 1
        return trim($result->getStdOut());
80
    }
81
}
82