Completed
Pull Request — master (#1)
by Billie
01:57
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 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\Cli\Command\Runner\Result;
13
use SebastianFeldmann\Git\Command\Config\Get;
14
15
/**
16
 * Class Config
17
 *
18
 * @package SebastianFeldmann\Git
19
 * @author  Sebastian Feldmann <[email protected]>
20
 * @link    https://github.com/sebastianfeldmann/git
21
 */
22
class Config extends Base
23
{
24
    /**
25
     * Does git have a configuration key
26
     *
27
     * @param  string $name
28
     * @return boolean
29
     */
30 1
    public function has(string $name) : bool
31
    {
32 1
        $result = $this->configCommand($name);
33
34 1
        return $result->isSuccessful();
35
    }
36
37
38
    /**
39
     * Get a configuration key value
40
     *
41
     * @param  string $name
42
     * @return string
43
     */
44 1
    public function get(string $name) : string
45
    {
46 1
        $result = $this->configCommand($name);
47
48 1
        return $result->getBufferedOutput()[0];
49
    }
50
51
    /**
52
     * Run the get config command
53
     *
54
     * @param string $name
55
     * @return \SebastianFeldmann\Cli\Command\Runner\Result
56
     */
57 2
    private function configCommand(string $name) : Result
58
    {
59 2
        $cmd = (new Get($this->repo->getRoot()));
60 2
        $cmd->name($name);
61
62 2
        $result = $this->runner->run($cmd);
63
64 2
        return $result;
65
    }
66
}
67