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

Git::exec()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 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