Passed
Push — master ( 9251f2...ca8fc4 )
by Herberto
03:14
created

GitAdapter   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 42
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findMostChangedFiles() 0 4 1
D parseGitEffortOutput() 0 26 9
1
<?php
2
3
namespace Hgraca\Phorensic\Miner\Vcs\Git;
4
5
use Hgraca\Phorensic\Miner\Vcs\VcsMinerInterface;
6
7
final class GitAdapter implements VcsMinerInterface
8
{
9
    /** @var ConsoleInterface */
10
    private $console;
11
12 1
    public function __construct(ConsoleInterface $console)
13
    {
14 1
        $this->console = $console;
15 1
    }
16
17 1
    public function findMostChangedFiles(string $repoPath, string $since = null): array
18
    {
19 1
        return $this->parseGitEffortOutput($this->console->gitEffort($repoPath, $since));
20
    }
21
22 1
    private function parseGitEffortOutput(string $gitEffortOutput)
23
    {
24 1
        $outputLines = explode(PHP_EOL, $gitEffortOutput);
25
26 1
        $foundFirstBlankLine = false;
27 1
        $relevantOutputLines = [];
28 1
        foreach ($outputLines as $line) {
29 1
            $foundSecondBlankLine = ($foundFirstBlankLine && $line === '') ? true : false;
30 1
            $foundFirstBlankLine = ($foundFirstBlankLine || $line === '') ? true : false;
31
32 1
            if ($foundSecondBlankLine) {
33 1
                break;
34
            }
35
36 1
            if (!$foundFirstBlankLine || $line === '') {
37 1
                continue;
38
            }
39
40 1
            $relevantLine = explode(' ', preg_replace('/\s+/', ' ', trim($line)));
41 1
            $relevantLine[0] = trim($relevantLine[0], ".");
42 1
            $relevantOutputLines[] = $relevantLine;
43
        }
44 1
        array_pop($relevantOutputLines);
45
46 1
        return $relevantOutputLines;
47
    }
48
}
49