Passed
Push — main ( 604bfc...f70419 )
by Sebastian
04:51
created

PrePush   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 87
rs 10
ccs 14
cts 14
cp 1
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A hash() 0 3 1
A id() 0 3 1
A branch() 0 3 1
A isZeroRev() 0 3 1
A head() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of CaptainHook.
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Git\Rev;
13
14
use CaptainHook\App\Git\Rev;
15
16
/**
17
 * Git pre-push reference
18
 *
19
 * @package CaptainHook
20
 * @author  Sebastian Feldmann <[email protected]>
21
 * @link    https://github.com/captainhookphp/captainhook
22
 * @since   Class available since Release 5.15.0
23
 */
24
class PrePush implements Rev
25
{
26
    /**
27
     * Head path - refs/heads/main
28
     *
29
     * @var string
30
     */
31
    private string $head;
32
33
    /**
34
     * Git hash
35
     *
36
     * @var string
37
     */
38
    private string $hash;
39
40
    /**
41
     * Branch name
42
     *
43
     * @var string
44
     */
45
    private string $branch;
46
47
    /**
48
     * Constructor
49
     *
50
     * @param string $head
51
     * @param string $hash
52
     * @param string $branch
53
     */
54 14
    public function __construct(string $head, string $hash, string $branch)
55
    {
56 14
        $this->head   = $head;
57 14
        $this->hash   = $hash;
58 14
        $this->branch = $branch;
59
    }
60
61
    /**
62
     * Head getter
63
     *
64
     * @return string
65
     */
66 1
    public function head(): string
67
    {
68 1
        return $this->head;
69
    }
70
71
    /**
72
     * Hash getter
73
     *
74
     * @return string
75
     */
76 1
    public function hash(): string
77
    {
78 1
        return $this->hash;
79
    }
80
81
    /**
82
     * Branch getter
83
     *
84
     * @return string
85
     */
86 9
    public function branch(): string
87
    {
88 9
        return $this->branch;
89
    }
90
91
    /**
92
     * Returns the ref id that can be used in a git command
93
     *
94
     * This can be completely different thing hash, branch name, ref-log position...
95
     *
96
     * @return string
97
     */
98 10
    public function id(): string
99
    {
100 10
        return $this->hash;
101
    }
102
103
    /**
104
     * Is this a git dummy hash
105
     *
106
     * @return bool
107
     */
108 7
    public function isZeroRev(): bool
109
    {
110 7
        return Util::isZeroHash($this->hash);
111
    }
112
}
113