Completed
Pull Request — master (#9)
by Rafael Gonçalves
03:18
created

Git   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 55
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getGitDirInConfiguration() 0 5 1
A GitDirExist() 0 7 1
A shellExec() 0 7 1
A exec() 0 7 1
1
<?php
2
namespace Kendrick\SymfonyDebugToolbarGit\Git;
3
4
use Symfony\Component\DependencyInjection\ContainerInterface;
5
class Git
6
{
7
    protected $container;
8
9
    public function __construct(ContainerInterface $container)
10
    {
11
        $this->container = $container;
12
    }
13
14
    /**
15
     *
16
     * @return string  The Git direcotry especificated in config_dev
17
     */
18
    public function getGitDirInConfiguration()
19
    {
20
        $gitDir = $this->container->getParameter('symfony_debug_toolbar_git.repository_local_dir') . '/.git';
21
        return $gitDir;
22
    }
23
24
    /**
25
     * verifies that the directory exists
26
     * @return bool
27
     */
28
    public function GitDirExist()
29
    {
30
        $gitDir = $this->container->get('kernel')->getRootDir() . "/..";
31
        $gitDir .= $this->getGitDirInConfiguration();
32
33
        return file_exists($gitDir);
34
    }
35
36
    /**
37
     * @param $command
38
     * @return string
39
     */
40
    public final function shellExec($command)
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
41
    {
42
        $command = sprintf('cd %s && %s', $this->GitDirExist(), $command);
43
        $resultCommand = shell_exec($command);
44
45
        return (string)trim($resultCommand);
46
    }
47
48
    /**
49
     * @param $command
50
     * @return array
51
     */
52
    public final function exec($command)
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
53
    {
54
        $command = sprintf('cd %s && %s', $this->GitDirExist(), $command);
55
        exec($command, $resultCommand);
56
57
        return $resultCommand;
58
    }
59
}
60
61