Passed
Push — master ( 579314...f6d3c0 )
by Sebastian
02:05
created

OnBranch   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 4
c 1
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isTrue() 0 3 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
declare(strict_types=1);
13
14
namespace CaptainHook\App\Hook\Condition;
15
16
use CaptainHook\App\Console\IO;
17
use CaptainHook\App\Hook\Condition;
18
use SebastianFeldmann\Git\Repository;
19
20
/**
21
 * OnBranch condition
22
 *
23
 * @package CaptainHook
24
 * @author  Sebastian Feldmann <[email protected]>
25
 * @link    https://github.com/captainhookphp/captainhook
26
 * @since   Class available since Release 5.0.0
27
 */
28
class OnBranch implements Condition
29
{
30
    /**
31
     * Branch name to compare
32
     *
33
     * @var string
34
     */
35
    private $name;
36
37
    /**
38
     * OnBranch constructor.
39
     *
40
     * @param string $name
41
     */
42
    public function __construct(string $name)
43
    {
44
        $this->name = $name;
45
    }
46
47
    /**
48
     * Check is the current branch is equal to the configured one
49
     *
50
     * @param  \CaptainHook\App\Console\IO       $io
51
     * @param  \SebastianFeldmann\Git\Repository $repository
52
     * @return bool
53
     */
54
    public function isTrue(IO $io, Repository $repository): bool
55
    {
56
        return trim($repository->getInfoOperator()->getCurrentBranch()) === $this->name;
57
    }
58
}
59