Completed
Pull Request — master (#1)
by Billie
01:48
created

Config::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of CaptainHook.
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
11
namespace SebastianFeldmann\Git\Operator;
12
13
use SebastianFeldmann\Git\Command\Config\Get;
14
use SebastianFeldmann\Git\Command\Config\ListAll;
15
16
/**
17
 * Class Config
18
 *
19
 * @package SebastianFeldmann\Git
20
 * @author  Sebastian Feldmann <[email protected]>
21
 * @link    https://github.com/sebastianfeldmann/git
22
 * @since   Class available since Release 0.9.0
23
 */
24
class Config extends Base
25
{
26
    /**
27
     * If git has a configuration key
28
     *
29
     * @param  string $name
30
     *
31
     * @return boolean
32
     */
33 1
    public function has(string $name): bool
34
    {
35 1
        $result = $this->configCommand($name);
36
37 1
        return $result->isSuccessful();
38
    }
39
40
41
    /**
42
     * Get a configuration key value
43
     *
44
     * @param  string $name
45
     *
46
     * @return string
47
     */
48 1
    public function get(string $name): string
49
    {
50 1
        $result = $this->configCommand($name);
51
52 1
        return $result->getBufferedOutput()[0];
53
    }
54
55
    /**
56
     * @param string $name
57
     *
58
     * @return \SebastianFeldmann\Cli\Command\Runner\Result
59
     */
60 2
    private function configCommand(string $name)
61
    {
62 2
        $cmd = (new Get($this->repo->getRoot()));
63 2
        $cmd->name($name);
64
65 2
        $result = $this->runner->run($cmd);
66
67 2
        return $result;
68
    }
69
}
70