FilesCommittedExtractor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 11 2
A getFiles() 0 6 1
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