FilesCommittedExtractor::getFiles()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace PhpGitHooks\Module\Git\Infrastructure\Files;
4
5
class FilesCommittedExtractor
6
{
7
    /** @var array */
8
    private $output = array();
9
    /** @var int */
10
    private $rc = 0;
11
12
    private function execute()
13
    {
14
        exec('git rev-parse --verify HEAD 2> /dev/null', $this->output, $this->rc);
15
16
        $against = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
17
        if ($this->rc === 0) {
18
            $against = 'HEAD';
19
        }
20
21
        exec("git diff-index --cached --name-status $against | egrep '^(A|M)' | awk '{print $2;}'", $this->output);
22
    }
23
24
    /**
25
     * @return array
26
     */
27
    public function getFiles()
28
    {
29
        $this->execute();
30
31
        return $this->output;
32
    }
33
}
34