Completed
Push — master ( 3eb340...e90908 )
by Sebastian
04:27
created

Base::getAcceptableExitCodes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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\Command;
11
12
use SebastianFeldmann\Cli\Command;
13
14
/**
15
 * Class Base
16
 *
17
 * @package SebastianFeldmann\Git
18
 * @author  Sebastian Feldmann <[email protected]>
19
 * @link    https://github.com/sebastianfeldmann/git
20
 * @since   Class available since Release 0.9.0
21
 */
22
abstract class Base implements Command
23
{
24
    /**
25
     * Repository root directory.
26
     *
27
     * @var string
28
     */
29
    protected $repositoryRoot;
30
31
    /**
32
     * Base constructor.
33
     *
34
     * @param string $root
35
     */
36 26
    public function __construct(string $root = '')
37
    {
38 26
        $this->repositoryRoot = $root;
39 26
    }
40
41
    /**
42
     * Return cli command to execute.
43
     *
44
     * @return string
45
     */
46 14
    public function getCommand() : string
47
    {
48
        $command = 'git'
49 14
                 . $this->getRootOption()
50 14
                 . ' '
51 14
                 . $this->getGitCommand();
52 14
        return $command;
53
    }
54
55
    /**
56
     * Return list of acceptable exit codes.
57
     *
58
     * @return array
59
     */
60 1
    public function getAcceptableExitCodes() : array
61
    {
62 1
        return [0];
63
    }
64
65
    /**
66
     * Do we need the -C option.
67
     *
68
     * @return string
69
     */
70 14
    protected function getRootOption() : string
71
    {
72 14
        $option = '';
73
        // if root is set
74 14
        if (!empty($this->repositoryRoot)) {
75
            // and it's not the current working directory
76 1
            if (getcwd() !== $this->repositoryRoot) {
77 1
                $option =  ' -C ' . escapeshellarg($this->repositoryRoot);
78
            }
79
80
        }
81 14
        return $option;
82
    }
83
84
    /**
85
     * Auto cast method.
86
     *
87
     * @return string
88
     */
89 4
    public function __toString() : string
90
    {
91 4
        return $this->getCommand();
92
    }
93
94
    /**
95
     * Return the command to execute.
96
     *
97
     * @return string
98
     * @throws \RuntimeException
99
     */
100
    protected abstract function getGitCommand() : string;
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
101
}
102