Completed
Pull Request — master (#1)
by Billie
03:49 queued 01:55
created

Config   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 45
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A has() 0 6 1
A get() 0 6 1
A configCommand() 0 9 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
namespace SebastianFeldmann\Git\Operator;
11
12
use SebastianFeldmann\Cli\Command\Runner\Result;
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
 */
23
class Config extends Base
24
{
25
    /**
26
     * Does git have a configuration key
27
     *
28
     * @param  string $name
29
     * @return boolean
30
     */
31 1
    public function has(string $name) : bool
32
    {
33 1
        $result = $this->configCommand($name);
34
35 1
        return $result->isSuccessful();
36
    }
37
38
39
    /**
40
     * Get a configuration key value
41
     *
42
     * @param  string $name
43
     * @return string
44
     */
45 1
    public function get(string $name) : string
46
    {
47 1
        $result = $this->configCommand($name);
48
49 1
        return $result->getBufferedOutput()[0];
50
    }
51
52
    /**
53
     * Run the get config command
54
     *
55
     * @param string $name
56
     * @return \SebastianFeldmann\Cli\Command\Runner\Result
57
     */
58 2
    private function configCommand(string $name) : Result
59
    {
60 2
        $cmd = (new Get($this->repo->getRoot()));
61 2
        $cmd->name($name);
62
63 2
        $result = $this->runner->run($cmd);
64
65 2
        return $result;
66
    }
67
}
68