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

Git   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 45
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getGitDir() 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
6
class Git
7
{
8
    protected $container;
9
10
    public function __construct(ContainerInterface $container)
11
    {
12
        $this->container = $container;
13
    }
14
15
    /**
16
     * verifies that the directory exists
17
     * @return bool
18
     */
19
    public function getGitDir()
20
    {
21
        $gitDir = $this->container->get('kernel')->getRootDir()."/../";
22
        $gitDir .= $this->container->getParameter('symfony_debug_toolbar_git.repository_local_dir').'.git';
23
24
        return $gitDir;
25
    }
26
27
    /**
28
     * @param $command
29
     * @return string
30
     */
31
    public function shellExec($command)
32
    {
33
        $command = sprintf('cd %s && %s', $this->getGitDir(), $command);
34
        $resultCommand = shell_exec($command);
35
36
        return (string)trim($resultCommand);
37
    }
38
39
    /**
40
     * @param $command
41
     * @return array
42
     */
43
    public function exec($command)
44
    {
45
        $command = sprintf('cd %s && %s', $this->getGitDir(), $command);
46
        exec($command, $resultCommand);
47
48
        return $resultCommand;
49
    }
50
}
51