Completed
Push — master ( 3952c5...023801 )
by Sebastian
02:12
created

Base   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 75
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCommand() 0 13 1
A getRootOption() 0 13 3
A __toString() 0 4 1
getGitCommand() 0 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
 */
19
abstract class Base implements Command
20
{
21
    /**
22
     * Repository root directory
23
     *
24
     * @var string
25
     */
26
    protected $repositoryRoot;
27
28
    /**
29
     * Base constructor.
30
     *
31
     * @param string $root
32
     */
33 19
    public function __construct(string $root = '')
34
    {
35 19
        $this->repositoryRoot = $root;
36 19
    }
37
38
    /**
39
     * Return cli command to execute.
40
     *
41
     * @return string
42
     */
43 13
    public function getCommand() : string
44
    {
45
        $command = 'git'
46 13
                 . $this->getRootOption()
47 13
                 . ' '
48 13
                 . $this->getGitCommand();
49
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
        if (DIRECTORY_SEPARATOR == '/') {
51
            $command = 'LC_ALL=en_US.UTF-8 ' . $command;
52
        }
53
        */
54 13
        return $command;
55
    }
56
57
    /**
58
     * Do we need the -C option.
59
     *
60
     * @return string
61
     */
62 13
    protected function getRootOption() : string
63
    {
64 13
        $option = '';
65
        // if root is set
66 13
        if (!empty($this->repositoryRoot)) {
67
            // and it's not the current working directory
68 1
            if (getcwd() !== $this->repositoryRoot) {
69 1
                $option =  ' -C ' . escapeshellarg($this->repositoryRoot);
70
            }
71
72
        }
73 13
        return $option;
74
    }
75
76
    /**
77
     * Auto cast method.
78
     *
79
     * @return string
80
     */
81 4
    public function __toString() : string
82
    {
83 4
        return $this->getCommand();
84
    }
85
86
    /**
87
     * Return the command to execute.
88
     *
89
     * @return string
90
     * @throws \RuntimeException
91
     */
92
    protected abstract function getGitCommand() : string;
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
93
}
94